]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge of (#10766) to Vaadin 7.
authorAnna Koskinen <anna@vaadin.com>
Fri, 1 Feb 2013 11:07:20 +0000 (13:07 +0200)
committerAnna Koskinen <anna@vaadin.com>
Fri, 1 Feb 2013 13:23:36 +0000 (15:23 +0200)
Fix case where ComboBox suggestion menu selects a wrong item if there
are duplicate captions.

Change-Id: Ia2e6502f328f5f6daca74e6b60bd3b6ffb7ad977

client/src/com/vaadin/client/ui/VFilterSelect.java
uitest/src/com/vaadin/tests/components/combobox/ComboBoxDuplicateCaption.java [new file with mode: 0644]

index d493386beb860452bb9890c77580120bfe34d95d..cea3489b42e6ba19235991a3a8635fe8e3835655 100644 (file)
@@ -1663,8 +1663,10 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
                 tabPressedWhenPopupOpen = false;
                 suggestionPopup.menu.doSelectedItemAction();
                 suggestionPopup.hide();
-            } else if (!suggestionPopup.isAttached()
+            } else if ((!suggestionPopup.isAttached() && waitingForFilteringResponse)
                     || suggestionPopup.isJustClosed()) {
+                // typing so fast the popup was never opened, or it's just
+                // closed
                 suggestionPopup.menu.doSelectedItemAction();
             }
             if (selectedOptionKey == null) {
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxDuplicateCaption.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxDuplicateCaption.java
new file mode 100644 (file)
index 0000000..3c1e8a2
--- /dev/null
@@ -0,0 +1,66 @@
+package com.vaadin.tests.components.combobox;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Log;
+import com.vaadin.tests.util.Person;
+import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxDuplicateCaption extends TestBase {
+
+    private Log log = new Log(5);
+
+    @Override
+    protected void setup() {
+        List<Person> list = new ArrayList<Person>();
+        Person p1 = new Person();
+        p1.setFirstName("John");
+        p1.setLastName("Doe");
+        list.add(p1);
+
+        Person p2 = new Person();
+        p2.setFirstName("Jane");
+        p2.setLastName("Doe");
+        list.add(p2);
+
+        BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+                Person.class);
+        container.addAll(list);
+
+        ComboBox box = new ComboBox("Duplicate captions test Box");
+        box.setId("ComboBox");
+        box.setImmediate(true);
+        box.addValueChangeListener(new ValueChangeListener() {
+
+            public void valueChange(
+                    com.vaadin.data.Property.ValueChangeEvent event) {
+                Person p = (Person) event.getProperty().getValue();
+                log.log("Person = " + p.getFirstName() + " " + p.getLastName());
+            }
+        });
+        box.setContainerDataSource(container);
+        box.setItemCaptionMode(ItemCaptionMode.PROPERTY);
+        box.setItemCaptionPropertyId("lastName");
+
+        addComponent(log);
+
+        addComponent(box);
+        addComponent(new Button("Focus this"));
+    }
+
+    @Override
+    protected String getDescription() {
+        return "VFilterSelects with duplicate item captions should not try to do a select (exact match search) for onBlur if not waitingForFilteringResponse";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 10766;
+    }
+}