Results 1 to 2 of 2

Thread: Add items to combobox store multiple times

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksterra, Norway
    Posts
    71

    Default Add items to combobox store multiple times

    When the store connected to a ComboBox are cleared and re-filled, you might run into situations where the ListView fails while adding items. This is illustrated by the following example:

    Code:
    public class ListViewMultiAdd implements EntryPoint {
    
    
        @Override
        public final void onModuleLoad() {
            final ListStore<String> store = new ListStore<>(new ModelKeyProvider<String>() {
                @Override
                public String getKey(final String item) {
                    return item;
                }
            });
    
    
            final ComboBox<String> comboBox = new ComboBox<>(store, new LabelProvider<String>() {
                @Override
                public String getLabel(final String item) {
                    return item;
                }
            });
            RootPanel.get().add(comboBox, 10, 10);
    
    
            final TextButton add = new TextButton("Add items");
            add.addSelectHandler(new SelectHandler() {
                @Override
                public void onSelect(final SelectEvent event) {
                    store.clear();
                    store.addAll(Arrays.asList("Test 1", "Test 2"));
                    store.addAll(Arrays.asList("Test 3", "Test 4"));
                }
            });
            RootPanel.get().add(add, 200, 10);
        }
    }
    • Press "Add items"
    • Open combobox
    • Press "Add items" again
    • See that ListView produces an error
    • See that the combobox has the two first items only

  2. #2
    Sencha User
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    98

    Default

    Clear the ComboBox as well in onSelect. It will work

Posting Permissions

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