Results 1 to 7 of 7

Thread: Setting value of ComboBox attached to remote Store without having to preload Store

  1. #1
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    15
    Vote Rating
    10
      0  

    Default 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:

    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
    });
    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?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    15
    Vote Rating
    10
      0  

    Default

    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.

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    May 2007
    Posts
    196
    Vote Rating
    0
      0  

    Default

    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...

  6. #6
    Sencha User
    Join Date
    May 2007
    Posts
    196
    Vote Rating
    0
      0  

    Default

    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.

  7. #7
    Sencha User
    Join Date
    Jun 2008
    Posts
    138
    Vote Rating
    7
      0  

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •