PDA

View Full Version : Populate a combobox from php/ajax?



wakatanka
30 Jun 2010, 11:33 AM
Hi i've put on my app this combobox component:



Forms = new Ext.form.FormPanel({
items: [{
xtype: 'select',
name: 'rank',
cls: 'selez',
options: [{
text: 'Master',
value: 'master'
},
{
text: 'Student',
value: 'padawan'
}]
}]
});



how can i put option value from ajax/php instead hard coding (master/student)??

thanks

TommyMaintz
30 Jun 2010, 11:38 AM
We are going to have to enhance the Select component to allow changing the values after the component has initially rendered.
For now you can make an ajax request and in the callback, decode the json response using Ext.decode and then pass the items you want to put in your select into the options configuration. Note that you have to create the Select at that time. Then add the select into the formpanel.

An (untested and incomplete) example of how this ties together.


Ext.Ajax.request({
url: 'yoururl.json',
callback: function (options, success, response) {
var options = Ext.decode(response.responseText).options;
yourFormPanel.add({
xtype: 'select',
name: 'rank',
cls: 'selez',
options: options
});
yourFormPanel.doComponentLayout();
//yourFormPanel.doLayout() will be enough if you dont have dockeditems in your formpanel.
}
});


Again, we will make this much easier in an upcoming version.

wakatanka
1 Jul 2010, 7:42 AM
Hi Tommy, thanks for the response, i've tryed but with no luck, can you show me a working example?

thanks