]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Combobox adding an item with empty string (#11067)
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>
Wed, 18 Jul 2018 10:10:31 +0000 (13:10 +0300)
committerIlia Motornyi <elmot@vaadin.com>
Wed, 18 Jul 2018 10:10:31 +0000 (13:10 +0300)
server/src/main/java/com/vaadin/ui/ComboBox.java

index 5d4a3f4f54c0ac9d418a3329f3749d4579758794..0a5a36c8568e23ed3a703bab5cdcfac86eb1b224 100644 (file)
@@ -186,24 +186,22 @@ public class ComboBox<T> extends AbstractSingleSelect<T>
         @Override
         public void createNewItem(String itemValue) {
             // New option entered
+            boolean added = false;
             if (itemValue != null && !itemValue.isEmpty()) {
                 if (getNewItemProvider() != null) {
                     Optional<T> item = getNewItemProvider().apply(itemValue);
-                    if (!item.isPresent()) {
-                        // ensure the client resets the value to previous
-                        // selection
-                        getRpcProxy(ComboBoxClientRpc.class)
-                                .newItemNotAdded(itemValue);
-                    }
+                    added = item.isPresent();
                 } else if (getNewItemHandler() != null) {
                     getNewItemHandler().accept(itemValue);
-                } else {
-                    // selection handling is needed at the client even if
-                    // NewItemHandler is missing
-                    getRpcProxy(ComboBoxClientRpc.class)
-                            .newItemNotAdded(itemValue);
+                    // Up to the user to tell if no item was added.
+                    added = true;
                 }
             }
+
+            if (!added) {
+                // New item was not handled.
+                getRpcProxy(ComboBoxClientRpc.class).newItemNotAdded(itemValue);
+            }
         }
 
         @Override