1. #1
    Ext User
    Join Date
    Nov 2008
    Posts
    7
    Vote Rating
    0
    Laugh10704 is on a distinguished road

      0  

    Default [FIXED] [1.1] ComboBox setModelStringProvider doesn't work

    [FIXED] [1.1] ComboBox setModelStringProvider doesn't work


    I've noticed that setting a ModelStringProvider on ComboBox doesn't work. If I set a displayField on the ComboBox, my ModelStringProvider doesn't get called at all. If I don't set a displayField on the ComboBox, my ModelStringProvider gets called with the property "text"; Returning anything from the ModelStringProvider in this case produces an empty dropdown.

    Code:

    Code:
    Map data1 = new HashMap();
    Map data2 = new HashMap();
    
    data1.put("name", "User 1");
    data2.put("name", "User 2");
    
    FormPanel panel = new FormPanel();
    
    ListStore store = new ListStore();
    store.add(new BaseModelData(data1));
    store.add(new BaseModelData(data2));
    
    ComboBox myBox = new ComboBox();
    myBox.setStore(store);
    
    myBox.setModelStringProvider(new ModelStringProvider() {
       public String getStringValue(ModelData modelData, String s) {
          return "ANYTHING";
       }
    });
    
    // it doesn't matter if this is commented in or not
    //myBox.setDisplayField("name");
    
    panel.add(myBox);
    
    panel.layout();
    
    RootPanel.get().add(panel);
    In the code above, the dropdown has two items but nothing is displayed (should be "ANYTHING" displayed twice). If you comment in "myBox.setDisplayField('name')" then the ComboBox has text, but it's "User 1" and "User 2", not "ANYTHING" twice.

  2. #2
    Sencha - GXT Dev Team darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
    darrellmeyer is on a distinguished road

      0  

    Default


    ModelStringProvider support is not implemented with the current ComboBox code. I have now deprecated its use. The same type of functionality is provided via of the new ModelProcessor class. See the following code:


    Code:
      public void onModuleLoad() {
        ListStore<State> states = new ListStore<State>();
        states.add(TestData.getStates());
    
        ComboBox<State> combo = new ComboBox<State>();
        combo.setStore(states);
        combo.setSimpleTemplate("{test}");
        combo.setWidth(200);
    
        // format the list values
        combo.getView().setModelProcessor(new ModelProcessor<State>() {
          public State prepareData(State model) {
            model.set("test", model.getAbbr() + " " + model.getName());
            return model;
          }
        });
        
        // format combo display value
        combo.setPropertyEditor(new ListModelPropertyEditor<State>(){
          @Override
          public String getStringValue(State value) {
            return value.getAbbr() + " " + value.getName();
          }
        });
        RootPanel.get().add(combo);
      }
    The new code is in SVN. With the current code, you can use a custom XTemplate to format the data used in the combos list. See the ComboBoxExample class for an example.

  3. #3
    Ext User
    Join Date
    Jun 2008
    Posts
    365
    Vote Rating
    0
    sdc is on a distinguished road

      0  

    Default


    Nice improvement, Darell. By the way, I'm not sure to see the differences between "format the list values" and "format combo display value". "format combo display value" = text of the associated LabelField ?

  4. #4
    Sencha - GXT Dev Team darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
    darrellmeyer is on a distinguished road

      0  

    Default


    format combo display value = text of the associated LabelField
    Yes.

Thread Participants: 2