I have a bobox and now I want to create a dynamic textfields on change of this bo box in Extjs 4 and i am following the Mvc structure of Extjs . Mybo is below
{
xtype : 'bo',
store : 'product.CategoryComboBox',
name: 'category',
id:'category',
displayField: 'name',
valueField: 'idProductCategory',
multiSelect : false,
fieldLabel: 'Category',
allowBlank: false,
allowQueryAll : false,
forceSelection : true,
typeAhead: true,
triggerAction: 'all',
delimiter : ',',
width: 300,
queryMode:'local',
listeners:{select:{fn:function(bo, value) {}
}
I have a bobox and now I want to create a dynamic textfields on change of this bo box in Extjs 4 and i am following the Mvc structure of Extjs . Mybo is below
{
xtype : 'bo',
store : 'product.CategoryComboBox',
name: 'category',
id:'category',
displayField: 'name',
valueField: 'idProductCategory',
multiSelect : false,
fieldLabel: 'Category',
allowBlank: false,
allowQueryAll : false,
forceSelection : true,
typeAhead: true,
triggerAction: 'all',
delimiter : ',',
width: 300,
queryMode:'local',
listeners:{select:{fn:function(bo, value) {}
}
Share
Improve this question
asked Feb 6, 2013 at 9:50
anupkumaranupkumar
3574 gold badges14 silver badges29 bronze badges
3 Answers
Reset to default 3You can add a FieldSet like this to your form
{
xtype: 'fieldset',
itemId: 'field_container',
layout: 'anchor',
border: 0,
style: { padding: '0' },
fieldDefaults: {
// field defaults
},
defaultType: 'textfield'
}
so when the bobox changes its value you just do the following
var container = this.down('fieldset[itemId="field_container"]');
container.removeAll();
var fieldsToAdd = [
{ name: 'field1', xtype: 'textfield', value: 'xxxxxx' },
{ name: 'field2', xtype: 'textfield', value: 'yyyyyyy' }
];
container.add(fieldsToAdd);
this way you can decide what the fieldsToAdd contains based on the bobox value.
Set an id to the textfield, then configure the listeners
property of your bo as follows :
listeners: {
change: function (bo, value) {
Ext.get('idOfYourTextfield').setValue(value);
}
}
Field container allows to have multiple form fields on the same line, so you could do that:
{
xtype: 'fieldcontainer',
layout: 'hbox',
items: {
xtype: 'bo',
// your config here
listeners: {
change: function () {
this.up('fieldcontainer').add({
xtype: 'textfield',
value: this.getValue()
});
}
}
}
}
Edit
I guess you'll need to test if the text field already exists:
change: function () {
var ct = this.up('fieldcontainer'),
textField = ct.down('textfield');
if (textField) {
textField.setValue(this.getValue());
} else {
ct.add({
xtype: 'textfield',
value: this.getValue()
});
}
}