diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-07-18 13:10:31 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-07-18 13:10:31 +0300 |
commit | 5d368053f4e6bb90464a4d4ecaf8d4768a63e7ef (patch) | |
tree | def3f998904e7c2c5bc13eeb8db5db99c83bd875 /server | |
parent | 341997fd97c05f944f7f2368147722e04977cccf (diff) | |
download | vaadin-framework-5d368053f4e6bb90464a4d4ecaf8d4768a63e7ef.tar.gz vaadin-framework-5d368053f4e6bb90464a4d4ecaf8d4768a63e7ef.zip |
Fix Combobox adding an item with empty string (#11067)
Diffstat (limited to 'server')
-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 |