View Full Version : Dynamicallly populate fieldset from ajax request

24 Mar 2011, 12:59 AM
I've created a fieldset such as;

this.roleOptions = new Ext.form.FieldSet({
title: 'Company Roles',
id : 'companyRole',
height : 100,
defaultType: 'checkbox'

And use an ajax request to retrieve all the roles from the db and then iterate through them, trying to add checkboxes to the fieldset.

url: baseUrl + '/addressbook/company/get-roles',
method: 'GET',
success: function (result, request) {

Ext.iterate(Ext.decode(result.responseText).result, function(key, value){
Ext.getCmp('companyRole').items.add(new Ext.form.Checkbox({ boxLabel : key.group_name, value : key.id, labelSeparator: ''}));//id : 'companyGroup[]', boxLabel : key.group_name, value : key.id}));

}, scope : this

This is all done when the form is loaded but I don't see anything in the fieldset. If I put the items.add code outside the Ext.iterate I see checkboxes. I'm extremely confused as to why no checkboxes appear as the loop is working correctly.