1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    11
    Vote Rating
    0
    Blessed Geek is on a distinguished road

      0  

    Default ComboBox select(int) does not change model value.

    ComboBox select(int) does not change model value.


    Let's say that a combo box encapsulates three instances of the model Candidates:
    Obama,
    Romney,
    Santorum.

    Therefore, comboBox.select(1) would correlate to selecting model instance Romney.

    However, starting from first instantiation, what I find is that after comboBox.select(1), getValue() still returns null.

    i.e., performing select(int) does not spontaneously change the model value of the combo box.
    Which means I have to override select(int) to insert code to effect change in model value.

    Is this the expected behaviour?

    Or is it due to my combo box having gone thro a couple of class extensions and the original select action has gotten lost along the way. I doubt so because I did not override the select in anyway. I merely made an abstract generic combo box that would take in any Enum and convert it into a list of models for the combo box.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    In both 2.x and 3.0 (your post doesn't make it clear which you are trying to use), the select() methods only work when the listview is expanded - when the combo box is open. To change the value (as it says in the javadocs), use setValue().

    Code:
       * Select an item in the dropdown list by its numeric index in the list. This
       * function does NOT cause the select event to fire. The list must expanded
       * for this function to work, otherwise use #setValue.

  3. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    11
    Vote Rating
    0
    Blessed Geek is on a distinguished road

      0  

    Default


    I believe that setValue does not visually make the value appear as the selected item on the combobox.

    I need to programmatically select an item, just as thought a user clicked on the combo box a selected an item. GXT combo box does not seem to have the ability to emulate that user's action. It either
    • allows selecting an item programmatically without changing the value
    • or allows setting the value of the combo box without changing the combo box selection to reflect to the user that programmatically driven change.
    Let's say that I have a form with two combo boxes that would allow a user to pick artists and genre. Let us say that the current genre is Dance Rock and the artist is Madonna.

    If the user selects Country genre, then my form would spontaneously select Brad Paisley as the artist. If the user agrees, and clicks OK, the form would send to the server genre=Country, artist=Madonna, even though the user last saw the form as showing genre=Country, artist=Brad Paisley.

    Which means my combo box has to over-ride setValue, to make it change both the value and the selection.

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    I believe that setValue does not visually make the value appear as the selected item on the combobox.
    Unless I really am misunderstanding you, I'm not sure what leads you to that conclusion - here is a quick example with a ComboBox and two buttons. Each button can select a different value using setValue, and the comboBox can still be directly manipulated for selection. After values are selected, the buttons still work to change back to another value. These setValue calls could just as easily be put into your form setup, or called as part of handlers on other combos.

    Code:
    public class Test implements EntryPoint {
      @Override
      public void onModuleLoad() {
        ListStore<String> store = new ListStore<String>(new ModelKeyProvider<String>() {
          public String getKey(String item) {
            return item;
          }
        });
        store.add("one");
        store.add("two");
        store.add("three");
        final ComboBox<String> combo = new ComboBox<String>(store, new StringLabelProvider<String>());
        combo.setTriggerAction(TriggerAction.ALL);
        
        RootPanel.get().add(combo);
        
        TextButton btn = new TextButton("one", new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            combo.setValue("one");
          }
        });
        RootPanel.get().add(btn);
        
        TextButton btn2 = new TextButton("two", new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            combo.setValue("two");
          }
        });
        RootPanel.get().add(btn2);
      }
    }
    Test with both 3.0.0-rc and svn trunk. Let me know if adapting this example doesn't work for you, or you can't adapt it for your use case.

  5. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    11
    Vote Rating
    0
    Blessed Geek is on a distinguished road

      0  

    Default


    "Test with both 3.0.0-rc ... "

    I think we are only licensed for 2.x.

  6. #6
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    I mentioned earlier that you hadn't made it clear which version you were using, and when you didn't specify, I picked the latest.

    Same example in 2.x, same essential pieces in the code, same behavior:

    Code:
    public class Training implements EntryPoint {
    
      public void onModuleLoad() {
        final ComboBox<ModelData> combo = new ComboBox<ModelData>();
        ListStore<ModelData> listStore = new ListStore<ModelData>();
        final ModelData one = createData("one");
        listStore.add(one);
        final ModelData two = createData("two");
        listStore.add(two);
        final ModelData three = createData("three");
        listStore.add(three);
        
        combo.setStore(listStore);
        combo.setDisplayField("value");
        combo.setTriggerAction(TriggerAction.ALL);
        
        RootPanel.get().add(combo);
        
        Button btn = new Button("one", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            combo.setValue(one);
          }
        });
        RootPanel.get().add(btn);
        
        Button btn2 = new Button("two", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            combo.setValue(two);
          }
        });
        RootPanel.get().add(btn2);
        
      }
      
      private ModelData createData(String str) {
        BaseModelData data = new BaseModelData();
        data.set("value", str);
        return data;
      }
    
    }

Thread Participants: 1

Tags for this Thread