PDA

View Full Version : Dynamic Fieldset



mastachef
21 Dec 2011, 12:58 PM
Greetings.

I have looked at the API and search the forums to find a way to create a dynamic field set by changing the text of the field set and adding/removing an item. These actions would be based on an attribute that is returned in the JSON array.

The JSON Array may have one or two values


{ primaryProtocol: "test1", primaryStatus: 'ok'}
{ primaryProtocol: 'test1', primaryStatus: 'ok', secondaryProtocol: 'test2', secondaryStatus: 'bad'}



This is the fieldset for the status


var myfieldSet = new Ext.form.FieldSet ({
id: 'statusDisplay',
labelWidth: 272,
autoHeight: true,
autoWidth: true,
style: 'border:0; padding:0px 0px 0px 0px',
items: [{
itemId: 'primaryStatus',
xtype: 'cssfield',
editable: false
}, {
itemId: 'secondaryStatus',
xtype: 'cssfield',
editable: false
}]
});


If one notices, I do not have a fieldLabel for either item. What I would like to so is first add/remove an item based on whether the JSON array return one or two protocols.If it contains one, remove the second item from the fieldset and if two show up and the last returned value was one, add the item.

The second part of this is that I would like to set the fieldLabel text to what the primary and secondary protocols return and update accordingly. So, if 'foo' is returned, how does one set it?

I hope I was clear. Please let me know if you have and tips. Thank you.

mitchellsimoens
21 Dec 2011, 4:04 PM
To set a field label, the field should have a label property that is an Ext.Element instance so you can use the update method to update the html.

dorgan
22 Dec 2011, 10:38 AM
The JSON Array may have one or two values


{ primaryProtocol: "test1", primaryStatus: 'ok'}
{ primaryProtocol: 'test1', primaryStatus: 'ok', secondaryProtocol: 'test2', secondaryStatus: 'bad'}




You may want to change your JSON to return something like this:



{
protocols: [
{protocol: 'test1', status: 'ok'},
{protocol: 'test2', status: 'bad'}
]
}


Now you can loop through protocols and add each one to your fieldset.....And this is fully scalable......