-
30 Jul 2012 5:58 AM #1
ComboBox does not accept null value on enter key
ComboBox does not accept null value on enter key
Expected:Code:@Override public Widget asWidget() { VerticalLayoutContainer c = new VerticalLayoutContainer(); List<String> choice = Arrays.asList(null, "1", "2", "3"); ListStore<String> choiceStore = new ListStore<String>(new ModelKeyProvider<String>() { @Override public String getKey(String pItem) { return pItem; } }); choiceStore.addAll(choice); ComboBox<String> cb = new ComboBox<String>(choiceStore, new LabelProvider<String>() { @Override public String getLabel(String pItem) { return pItem; } }); c.add(cb); return c; }
When I navigate the ComboBox dropdown list with the arrow keys and press enter while the desired value is highlighted, the ComboBox should collapse and display the selected value.
Actual:
Selection works well for the values 1, 2 and 3. Selecting the null value by pressing the enter key does not work. The ComboBox does not collapse.
-
30 Jul 2012 6:12 AM #2
I moved this thread to the proper forum so we can take a look. Thanks for reporting.
-
12 Sep 2012 5:29 AM #3
Hi sven,
anything new on this one?
Thanks,
-hcr-
-
21 Nov 2012 1:08 AM #4
Hi there, any chance of getting that fixed any time soon?
Thanks and best regards,
-hcr-
-
21 Nov 2012 10:16 AM #5
I've spent a little time working on this, and have a few points to share:
The first issue here is that the example isn't valid - no item is allowed to have a null key. From the ModelKeyProvider javadocs:
The second again has to do with the value 'null' - what does it mean to select nothing? The ComboBox has a ListView that it uses to draw the dropdown, and when the enter key is hit, the ComboBox asks if anything was selected - it asks if the selected item isn't null. I'm changing this check to see if the list of selected items is _empty_ instead, and then finding the location of the null item.Code:/** * Gets a non-null key value that maps to this object. Keys must be consistent and * unique for a given model, as a database primary key would be used. */ String getKey(T item);
And one last thought: You can make the item draw full height in the combobox by telling the ComboBox in yet another way that the value null is okay. ComboBox internally uses a SimpleSafeHtmlCell<String> to render, which deliberately skips over null items. This can be replaced by taking over the ListView creation, and making your own cell that draws a null object as a . Here's my finished example, dealing with the first and third issues, and which I am using to find a good workaround for the second:
Code:public Widget asWidget() { VerticalLayoutContainer c = new VerticalLayoutContainer(); List<String> choice = Arrays.asList(null, "1", "2", "3"); ListStore<String> choiceStore = new ListStore<String>(new ModelKeyProvider<String>() { @Override public String getKey(String pItem) { return pItem + ""; } }); choiceStore.addAll(choice); ListView<String, String> listView = new ListView<String, String>(choiceStore, new IdentityValueProvider<String>(), new AbstractCell<String>() { @Override public void render(Cell.Context context, String value, SafeHtmlBuilder sb) { if (value == null) { sb.appendHtmlConstant(" "); } else { sb.appendEscaped(value); } } }); ComboBox<String> cb = new ComboBox<String>(choiceStore, new LabelProvider<String>() { @Override public String getLabel(String pItem) { return pItem; } }, listView); c.add(cb); return c; }
-
3 Dec 2012 10:59 AM #6
We've made a fix for this, which is now available in SVN and nightly builds, and will be in the next release. The fix was very nearly as described in my last post - check for an empty set of selected items, rather than asking if the current selected object is null.
Success! Looks like we've fixed this one. According to our records the fix was applied for
EXTGWT-2427
in
3.0.3.


Reply With Quote