PDA

View Full Version : Ajax populated Comboboxes in a Ajax populated form



netsuo
17 Jun 2010, 12:16 AM
Hi all,

I'm a long time ExtJS (now Sencha) user, but I'm facing a problem I never really correctly handled.
Let me explain.

Imagine a form that contains multiples comboboxes. Each combobox is linked to its own ajax datastore. Every combobox is working great, everyone has different valueField/displayField and the right value is sended trough te form's submit method.

Now, my form is receiving it's initial values from a remote store as well. The values are correctly put in the form.

My problem is: form's ajax received values that goes into comboboxes are linked to comboboxes' valueField. When the form's loaded, valueField's values are shown into comboboxes. That's a pretty normal behavior for me as comboboxes' stores aren't loaded at the time my form receive its values.
But I expected Sencha to update comboboxes displayValues after each store is loaded. And it's not the case.

For now, I added a "load" listener to each comboboxes' stores that basically do this:



load: function()
{
var c = Ext.ComponentMgr.get('the_combo');
c.setValue(c.originalValue);
}


Wich basically is a pain because I have PLENTY of ajax comboboxes in my forms. And on every store load you have to do Ext.ComponentMgr.get wich is a performance loss.

Is there a way to correctly use comboboxes with json stores AND using these in a form that obtain it's values via ajax ?

I know I could use a function before showing the form that will load every store and then show the form, but with like 10 comboboxes and stores, the "preloading" function would be huge and not so easy to manage (I really want the comboboxes stores to load simultaneously), and I want to avoid letting user wait on the load.

Thanks in advance and sorry for my English.

Stephane

Animal
17 Jun 2010, 12:18 AM
This is a very common problem which has been widely asked and discussed.

http://www.sencha.com/forum/showthread.php?75751-OPEN-42-ComboBox-s-setValue-call-with-a-remotely-loaded-Store

Condor's code in post #16 seems to be the best solution.

netsuo
17 Jun 2010, 12:41 AM
Wow that was fast !
Thanks a million Animal, I searched a lot but as English's not my main language, I didn't fid this post.

It's now working as expected and saved me a lot of code !