lastFilter.toLowerCase())) {
doItemAction(item, true);
} else {
- if (currentSuggestion != null) {
+ // currentSuggestion has key="" for nullselection
+ if (currentSuggestion != null
+ && !currentSuggestion.key.equals("")) {
+ // An item (not null) selected
String text = currentSuggestion.getReplacementString();
- /*
- * TODO? if (text.equals("")) {
- * addStyleDependentName(CLASSNAME_PROMPT);
- * tb.setText(inputPrompt); prompting = true; } else {
- * tb.setText(text); prompting = false;
- * removeStyleDependentName(CLASSNAME_PROMPT); }
- */
+ tb.setText(text);
selectedOptionKey = currentSuggestion.key;
+ } else {
+ // Null selected
+ tb.setText("");
+ selectedOptionKey = null;
}
}
suggestionPopup.hide();
--- /dev/null
+package com.vaadin.tests.components.combobox;\r
+\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.ui.ComboBox;\r
+\r
+public class ComboBoxValueInput extends TestBase {\r
+\r
+ @Override\r
+ protected void setup() {\r
+ ComboBox cb = new ComboBox("A combobox without input prompt");\r
+ cb.setImmediate(true);\r
+ cb.addItem("Value 1");\r
+ cb.addItem("Value 2");\r
+ cb.addItem("Value 3");\r
+\r
+ addComponent(cb);\r
+\r
+ cb = new ComboBox("A combobox with input prompt");\r
+ cb.setInputPrompt("Please select");\r
+ cb.setImmediate(true);\r
+ cb.addItem("Value 1");\r
+ cb.addItem("Value 2");\r
+ cb.addItem("Value 3");\r
+\r
+ addComponent(cb);\r
+\r
+ cb = new ComboBox("A combobox with null item");\r
+ cb.setInputPrompt("Please select");\r
+ cb.setImmediate(true);\r
+ cb.addItem("Null item");\r
+ cb.addItem("Value 1");\r
+ cb.addItem("Value 2");\r
+ cb.addItem("Value 3");\r
+ cb.setNullSelectionItemId("Null item");\r
+\r
+ addComponent(cb);\r
+\r
+ cb = new ComboBox("A combobox with null item and input prompt");\r
+ cb.setImmediate(true);\r
+ cb.addItem("Null item");\r
+ cb.addItem("Value 1");\r
+ cb.addItem("Value 2");\r
+ cb.addItem("Value 3");\r
+ cb.setNullSelectionItemId("Null item");\r
+\r
+ addComponent(cb);\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ return "A combobox should always show the selected value when it is not focused. Entering a text when nothing is selected and blurring the combobox should reset the value. The same should happen when a value is selected";\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ return 3268;\r
+ }\r
+\r
+}\r