-
17 Dec 2012 5:51 AM #1
Unanswered: Setting value of ComboBox attached to remote Store without having to preload Store
Unanswered: Setting value of ComboBox attached to remote Store without having to preload Store
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:
Simply by setting the combobox's skipStoreValidation config to true, we can now allow the original value to be set.Code: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 });
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?
-
19 Dec 2012 8:14 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
If the store is not loaded then the display field value is not present in the store.
IMO your solution is app specific.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
19 Dec 2012 8:18 AM #3
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.
-
19 Dec 2012 8:25 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
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.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
4 Jan 2013 5:14 AM #5
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...
-
4 Jan 2013 5:27 AM #6
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.
-
27 Mar 2013 5:28 AM #7
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?


Reply With Quote