From da8912fce63a7da163900e83a77991f308873eba Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 22 Sep 2009 08:36:47 +0000 Subject: [PATCH] Test case and fix for #3268 - ComboBox erroneus input is not always cleared svn changeset:8879/svn branch:6.1 --- .../terminal/gwt/client/ui/VFilterSelect.java | 17 +++--- .../combobox/ComboBoxValueInput.java | 59 +++++++++++++++++++ 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 src/com/vaadin/tests/components/combobox/ComboBoxValueInput.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index c0e51d7ec0..998abc157f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -490,16 +490,17 @@ public class VFilterSelect extends Composite implements Paintable, Field, 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(); diff --git a/src/com/vaadin/tests/components/combobox/ComboBoxValueInput.java b/src/com/vaadin/tests/components/combobox/ComboBoxValueInput.java new file mode 100644 index 0000000000..0d474daa54 --- /dev/null +++ b/src/com/vaadin/tests/components/combobox/ComboBoxValueInput.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.ComboBox; + +public class ComboBoxValueInput extends TestBase { + + @Override + protected void setup() { + ComboBox cb = new ComboBox("A combobox without input prompt"); + cb.setImmediate(true); + cb.addItem("Value 1"); + cb.addItem("Value 2"); + cb.addItem("Value 3"); + + addComponent(cb); + + cb = new ComboBox("A combobox with input prompt"); + cb.setInputPrompt("Please select"); + cb.setImmediate(true); + cb.addItem("Value 1"); + cb.addItem("Value 2"); + cb.addItem("Value 3"); + + addComponent(cb); + + cb = new ComboBox("A combobox with null item"); + cb.setInputPrompt("Please select"); + cb.setImmediate(true); + cb.addItem("Null item"); + cb.addItem("Value 1"); + cb.addItem("Value 2"); + cb.addItem("Value 3"); + cb.setNullSelectionItemId("Null item"); + + addComponent(cb); + + cb = new ComboBox("A combobox with null item and input prompt"); + cb.setImmediate(true); + cb.addItem("Null item"); + cb.addItem("Value 1"); + cb.addItem("Value 2"); + cb.addItem("Value 3"); + cb.setNullSelectionItemId("Null item"); + + addComponent(cb); + } + + @Override + protected String getDescription() { + 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"; + } + + @Override + protected Integer getTicketNumber() { + return 3268; + } + +} -- 2.39.5