From af15d54e5a49491ebadb9748381a22239ebf8ff7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 1 Jan 2016 12:02:06 +0200 Subject: Fixes exception when enter is pressed and there is nothing to select (#19149) Change-Id: I8ff11e98bb4ec999d369ff5bcde0cb95290ed037 --- client/src/com/vaadin/client/ui/VFilterSelect.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 99ebde1910..9459cc14a6 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -1861,8 +1861,16 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, case KeyCodes.KEY_ENTER: if (!allowNewItem) { - onSuggestionSelected(currentSuggestions - .get(suggestionPopup.menu.getSelectedIndex())); + int selected = suggestionPopup.menu.getSelectedIndex(); + if (selected != -1) { + onSuggestionSelected(currentSuggestions.get(selected)); + } else { + // The way VFilterSelect is done, it handles enter and tab + // in exactly the same way so we close the popup in both + // cases even though we could leave it open when pressing + // enter + suggestionPopup.hide(); + } } else { // Handle addition of new items. suggestionPopup.menu.doSelectedItemAction(); -- cgit v1.2.3