PDA

View Full Version : Setting value of ComboBox attached to remote Store without having to preload Store



ukjbrown
17 Dec 2012, 5:51 AM
I was extremely surprised to see that the out-of-the-box configuration of ComboBox doesn't appear to allow you to set the value of a ComboBox with a remote store unless the Store is loaded.

Essentially I have a form with many "lookup" combo boxes (approximately 15) - I want the value of these ComboBoxes to be set using loadRecord on the form, but I only want the underlying store to load if the user attempts to change that value. After all, it is unlikely they're going to change every field on the form!

If there is already a way to do this in ExtJS that I have missed, then please correct me, but from hours of investigation I couldn't find a reasonable way.

So, I came up with this (first attempt at a) solution:



Ext.define('My.patched.form.field.ComboBox, {
override: 'Ext.form.field.ComboBox,

setValue: function(value, doSelect) {
if(this.skipStoreValidation && !Ext.isEmpty(value) && !value.isModel && !(value instanceof Array)) {
var processedValue = value[this.valueField];
var rawValue = value[this.displayField];
this.displayTplData = [value];

this.setHiddenValue(processedValue);
this.value = processedValue;

this.setRawValue(this.getDisplayValue());
this.checkChange();

if(doSelect !== false) {
this.syncSelection();
}
this.applyEmptyText();
return this;
} else {
return this.callOverridden(arguments);
}
},

skipStoreValidation: false
});


Simply by setting the combobox's skipStoreValidation config to true, we can now allow the original value to be set.

Sure this will require some further tweaks, but seems to be working as expected for the moment.

Please could you build something like this into the framework?

mitchellsimoens
19 Dec 2012, 8:14 AM
If the store is not loaded then the display field value is not present in the store.

IMO your solution is app specific.

ukjbrown
19 Dec 2012, 8:18 AM
App specific?

I have been developing web applications for over 8 years and this is absolutely common practice. When the model is loaded from the server you have all the associations for that object available.

e.g. Person has a Dog (dog has its own fields that are loaded when the Person is retrieved from the server).

I am therefore quite able to VIEW the Person record and have his Dog's name populated in the Combobox without having to load any Dogs from the server.

Only when I want to change the Dog to another Dog do I need to access the Server.

I'm sorry, but why make more trips to the server than required? It simply increases the load time of the View/Edit form having to load the Store just to display a SINGLE value.

mitchellsimoens
19 Dec 2012, 8:25 AM
The concept isn't app specific, your solution is.

I personally want my store to be bound to the combobox tightly so if I need the display values there, I load the store upfront to have that data available. Request batching is what saves the extra calls.

temporary
4 Jan 2013, 5:14 AM
Same problem here.
Large amount of data (40.000+), paging enabled.

I have the required value for displayField and valueField, and I have found no way to set this as the default value.

Sorry, but this seems like a missing feature.
I would have to find the correct page to load the data firsthand. Seems unnecessary, since I already have all the required values...

temporary
4 Jan 2013, 5:27 AM
Ok, I have found a solution.

Although it is a remote store, I simply have set the data config, with one value, my desired default-value.
Together with the value config option, it now selects my default without doing an initial request.

jchau
27 Mar 2013, 5:28 AM
can you post your solution? if you set the data on the store with only your value, how do you make it load the rest of the records when user click on the dropdown arrow?