Success! Looks like we've fixed this one. According to our records the fix was applied for
EXTGWT-2427
in
3.0.3.
-
Sencha User
ComboBox does not accept null value on enter key
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;
}
Expected:
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.
-
I moved this thread to the proper forum so we can take a look. Thanks for reporting.
-
Sencha Premium Member
Hi sven,
anything new on this one?
Thanks,
-hcr-
-
Sencha Premium Member
Hi there, any chance of getting that fixed any time soon?
Thanks and best regards,
-hcr-
-
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:
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);
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.
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;
}
-
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.