Results 1 to 3 of 3

Thread: passing fields values

  1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    41

    Default passing fields values

    Hi I want to know how I can pass value of a field to other field in a same form :

    below is my Edit.js and I define a combo filed which get {id , name , family } from server as response
    and I want to also define a hidden field called customer_id and pass the id from the combo receives.

    Ext.define('WAITER.view.waiter.Edit', {
    extend: 'Ext.window.Window',
    alias : 'widget.waiteredit',


    requires: ['Ext.form.Panel',
    'Ext.form.field.Text'],


    stores: ['Customers','Waiters'],
    title : 'Edit Waiter',
    layout: 'fit',
    autoShow: true,
    width: 280,

    iconCls: 'icon-user',


    initComponent: function() {
    this.items = [
    {
    xtype: 'form',
    padding: '5 5 0 5',
    border: false,
    style: 'background-color: #fff;',

    fieldDefaults: {
    anchor: '100%',
    labelAlign: 'left',
    allowBlank: false,
    combineErrors: true,
    msgTarget: 'side'
    },


    items: [
    {
    xtype: 'textfield',
    name : 'id',
    fieldLabel: 'id',
    hidden:true
    },


    {
    xtype: 'textfield',
    name : 'customer_id',
    fieldLabel: 'customer_id',
    hidden:true // here I want to get id value from the combo field
    },








    {
    name : 'customer',
    xtype: 'combo', // here combo get a { id , name ,family } from the server
    store:'Customers',
    displayField: 'name',
    fieldLabel: 'customer',
    listConfig: {
    loadingText: 'Searching...',
    emptyText: 'No matching posts found.',


    // Custom rendering template for each item
    getInnerTpl: function() {

    return '{name}';
    }
    },
    pageSize: 10,
    width: 500,
    displayField: 'name'

    },






    {
    xtype: 'textfield',
    name : 'destination',
    fieldLabel: 'destination'
    },
    {
    xtype: 'datefield',
    name : 'from_date',
    fieldLabel: 'from_date'
    },
    {
    xtype: 'datefield',
    name : 'to_date',
    fieldLabel: 'to_date'
    },
    {
    xtype: 'textfield',
    name : 'from_cost',
    fieldLabel: 'from_cost'
    },
    {
    xtype: 'textfield',
    name : 'to_cost',
    fieldLabel: 'to_cost'
    },
    {
    xtype: 'textfield',
    name : 'hotel_stars',
    fieldLabel: 'hotel_stars'
    },
    {
    xtype: 'textfield',
    name : 'airline',
    fieldLabel: 'airline'
    },
    {
    xtype: 'textfield',
    name : 'sure',
    fieldLabel: 'sure'
    },
    {
    xtype: 'textfield',
    name : 'visited',
    fieldLabel: 'visited'
    },
































    ]
    }
    ];

    this.dockedItems = [{
    xtype: 'toolbar',
    dock: 'bottom',
    id:'buttons',
    ui: 'footer',
    items: ['->', {
    iconCls: 'icon-save',
    itemId: 'save',
    text: 'Save',
    action: 'save'
    },{
    iconCls: 'icon-reset',
    text: 'Cancel',
    scope: this,
    handler: this.close
    }]
    }];


    this.callParent(arguments);
    }
    });

  2. #2
    chramer's Avatar
    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    316
    Answers
    64

    Default

    First, set a valueField for the combobox.
    Code:
    valueField: 'id'
    Than just set hidden field value on 'change' event of the combobox

  3. #3
    Sencha User sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,335
    Answers
    124

    Default Use select event

    Hi nimaous,

    If you want to set field value of hidden text field same as combobox id, you must use select event of combobox something like that
    Code:
    listeners:{     
         select : function(combo, record, opt){
             var hiddenTextField = this.ownerCt.findField('name', 'customer_id');
                  ,  id = record.get('id');
             hiddenTextField .setValue(id);
         }
    }
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •