diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-07-18 13:10:31 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-07-30 16:45:46 +0300 |
commit | f9cf3a616dd021f5216dad526fff363274dbb3af (patch) | |
tree | 993b456dc557f6fb60f2fef0aa4fc9bec9df8668 | |
parent | 1db391038597687ed01406d7b7f466205d634f39 (diff) | |
download | vaadin-framework-f9cf3a616dd021f5216dad526fff363274dbb3af.tar.gz vaadin-framework-f9cf3a616dd021f5216dad526fff363274dbb3af.zip |
Fix Combobox adding an item with empty string (#11067)
(cherry picked from commit 5d36805)
-rw-r--r-- | server/src/main/java/com/vaadin/ui/ComboBox.java | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index 5d4a3f4f54..0a5a36c856 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -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 |