PDA

View Full Version : creating dynamic fields in a form



bertoost
9 Sep 2010, 1:24 AM
Hi all,

We're using ModX cms wich is using Extjs and I'm wondering how to create a form that is build on database records. To explain something more detailed;

I have a database table wich contains a list of categories. For each categorie I want to have an input textfield on my form. When this list of categories is changed the form must also change immediatly. The most beautifull way should be when I create a script file wich returns a json of xml string and the form will automatic be generated.

On my panel I have this items list now, wich creates what I want but it isn't dynamic...


...
items: [{
layout: 'form',
items: [{
html: 'Some page description here',
bodyStyle: 'margin-bottom: 25px;',
border: false
},{
xtype: 'numberfield',
fieldLabel: 'Categoryname 1',
name: 'group_1',
width: 50,
allowDecimals: false,
allowNegative: false
},{
xtype: 'numberfield',
fieldLabel: 'Categoryname 2',
name: 'group_2',
width: 50,
allowDecimals: false,
allowNegative: false
}
...
}]
...if someone has some experience with this; thanks already!

Regards, Bert

laurentParis
9 Sep 2010, 3:26 AM
try to set form into local var or use an ID for calling form with Ext.getCmp



var form = {
layout: 'form',
items: [{
html: 'Some page description here',
bodyStyle: 'margin-bottom: 25px;',
border: false
},{
xtype: 'numberfield',
fieldLabel: 'Categoryname 1',
name: 'group_1',
width: 50,
allowDecimals: false,
allowNegative: false
},{
xtype: 'numberfield',
fieldLabel: 'Categoryname 2',
name: 'group_2',
width: 50,
allowDecimals: false,
allowNegative: false
}
...
};
...
items: [
form
}]
...

form.add(new Ext.form.TextField({name: 'group_3'});
form.doLayout();

bertoost
9 Sep 2010, 5:41 AM
Okay! That will be a start... but how do I add fields per record from my database table? For example the same as an update or getlist script?