PDA

View Full Version : passing fields values



nimaous
26 May 2012, 4:28 AM
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);
}
});

chramer
26 May 2012, 5:55 AM
First, set a valueField (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.ComboBox-cfg-valueField) for the combobox.


valueField: 'id'

Than just set hidden field value on 'change' event of the combobox

sword-it
26 May 2012, 6:06 AM
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


listeners:{
select : function(combo, record, opt){
var hiddenTextField = this.ownerCt.findField('name', 'customer_id');
, id = record.get('id');
hiddenTextField .setValue(id);
}
}