From 5d368053f4e6bb90464a4d4ecaf8d4768a63e7ef Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 18 Jul 2018 13:10:31 +0300 Subject: [PATCH] Fix Combobox adding an item with empty string (#11067) --- .../src/main/java/com/vaadin/ui/ComboBox.java | 20 +++++++++---------- 1 file 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 extends AbstractSingleSelect @Override public void createNewItem(String itemValue) { // New option entered + boolean added = false; if (itemValue != null && !itemValue.isEmpty()) { if (getNewItemProvider() != null) { Optional 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 -- 2.39.5