summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMatti Tahvonen <matti@vaadin.com>2015-11-04 21:36:39 +0200
committerelmot <elmot@vaadin.com>2016-08-01 16:32:24 +0300
commitb5e8654eaba15cb611ac74395d813d10cc6fedb1 (patch)
treeefd6e28a45fd5c5b4e262d4133322d692f05284d /client
parent6688e6617275120bfc39cd31c464fd9b2a594a79 (diff)
downloadvaadin-framework-b5e8654eaba15cb611ac74395d813d10cc6fedb1.tar.gz
vaadin-framework-b5e8654eaba15cb611ac74395d813d10cc6fedb1.zip
Fix disappearing ComboBox value (#19221)
Without the fix, when selecting a value from page n+1 and re-opening the ComboBox popup, the content of the text box may disappear. Change-Id: I5fb57c0e5a068645f4b11fb1c392e682dd04b06a
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VFilterSelect.java45
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java51
2 files changed, 79 insertions, 17 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java b/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java
index 8411e05490..e3fe49871a 100644
--- a/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java
@@ -1871,6 +1871,18 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
// currentPage = -1; // forget the page
}
+
+ if (getSelectedCaption() != null && newKey.equals("")) {
+ // In scrollToPage(false) mode selecting null seems to be broken
+ // if current selection is not on first page. The above clause is so
+ // hard to interpret that new clause added here :-(
+ selectedOptionKey = newKey;
+ explicitSelectedCaption = null;
+ client.updateVariable(paintableId, "selected",
+ new String[] { selectedOptionKey }, immediate);
+ afterUpdateClientVariables();
+ }
+
suggestionPopup.hide();
}
@@ -2326,6 +2338,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
*/
boolean preventNextBlurEventInIE = false;
+ private String explicitSelectedCaption;
+
/*
* (non-Javadoc)
*
@@ -2366,7 +2380,11 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
focused = false;
if (!readonly) {
if (selectedOptionKey == null) {
- setPromptingOn();
+ if (explicitSelectedCaption != null) {
+ setPromptingOff(explicitSelectedCaption);
+ } else {
+ setPromptingOn();
+ }
} else if (currentSuggestion != null) {
setPromptingOff(currentSuggestion.caption);
}
@@ -2575,4 +2593,29 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
|| suggestionPopup.lazyPageScroller.isRunning();
}
+ /**
+ * Sets the caption of selected item, if "scroll to page" is disabled.
+ * This method is meant for internal use and may change in future versions.
+ *
+ * @since 7.7
+ * @param selectedCaption
+ * the caption of selected item
+ */
+ public void setSelectedCaption(String selectedCaption) {
+ explicitSelectedCaption = selectedCaption;
+ if (selectedCaption != null) {
+ setPromptingOff(selectedCaption);
+ }
+ }
+
+ /**
+ * This method is meant for internal use and may change in future versions.
+ *
+ * @since 7.7
+ * @return the caption of selected item, if "scroll to page" is disabled
+ */
+ public String getSelectedCaption() {
+ return explicitSelectedCaption;
+ }
+
}
diff --git a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
index c498f88dde..131485bc7b 100644
--- a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
@@ -35,8 +35,8 @@ import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.ui.ComboBox;
@Connect(ComboBox.class)
-public class ComboBoxConnector extends AbstractFieldConnector
- implements Paintable, SimpleManagedLayout {
+public class ComboBoxConnector extends AbstractFieldConnector implements
+ Paintable, SimpleManagedLayout {
// oldSuggestionTextMatchTheOldSelection is used to detect when it's safe to
// update textbox text by a changed item caption.
@@ -65,16 +65,15 @@ public class ComboBoxConnector extends AbstractFieldConnector
// work without additional UIDL messages
boolean noTextInput = uidl
.hasAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT)
- && uidl.getBooleanAttribute(
- ComboBoxConstants.ATTR_NO_TEXT_INPUT);
+ && uidl.getBooleanAttribute(ComboBoxConstants.ATTR_NO_TEXT_INPUT);
getWidget().setTextInputEnabled(!noTextInput);
// not a FocusWidget -> needs own tabindex handling
getWidget().tb.setTabIndex(getState().tabIndex);
if (uidl.hasAttribute("filteringmode")) {
- getWidget().filteringmode = FilteringMode
- .valueOf(uidl.getStringAttribute("filteringmode"));
+ getWidget().filteringmode = FilteringMode.valueOf(uidl
+ .getStringAttribute("filteringmode"));
}
getWidget().immediate = getState().immediate;
@@ -105,6 +104,13 @@ public class ComboBoxConnector extends AbstractFieldConnector
getWidget().suggestionPopupWidth = null;
}
+ if (uidl.hasAttribute("suggestionPopupWidth")) {
+ getWidget().suggestionPopupWidth = uidl
+ .getStringAttribute("suggestionPopupWidth");
+ } else {
+ getWidget().suggestionPopupWidth = null;
+ }
+
getWidget().suggestionPopup.updateStyleNames(uidl, getState());
getWidget().allowNewItem = uidl.hasAttribute("allownewitem");
@@ -181,12 +187,16 @@ public class ComboBoxConnector extends AbstractFieldConnector
// started.
if (selectedKeys.length > 0 && !selectedKeys[0].equals("")) {
performSelection(selectedKeys[0]);
+ // if selected key is available, assume caption is know based on
+ // it as well and clear selected caption
+ getWidget().setSelectedCaption(null);
+
} else if (!getWidget().waitingForFilteringResponse
&& uidl.hasAttribute("selectedCaption")) {
// scrolling to correct page is disabled, caption is passed as a
// special parameter
- getWidget().tb
- .setText(uidl.getStringAttribute("selectedCaption"));
+ getWidget().setSelectedCaption(
+ uidl.getStringAttribute("selectedCaption"));
} else {
resetSelection();
}
@@ -274,16 +284,16 @@ public class ComboBoxConnector extends AbstractFieldConnector
if (!getWidget().waitingForFilteringResponse
|| getWidget().popupOpenerClicked) {
if (!suggestionKey.equals(getWidget().selectedOptionKey)
- || suggestion.getReplacementString()
- .equals(getWidget().tb.getText())
+ || suggestion.getReplacementString().equals(
+ getWidget().tb.getText())
|| oldSuggestionTextMatchTheOldSelection) {
// Update text field if we've got a new
// selection
// Also update if we've got the same text to
// retain old text selection behavior
// OR if selected item caption is changed.
- getWidget()
- .setPromptingOff(suggestion.getReplacementString());
+ getWidget().setPromptingOff(
+ suggestion.getReplacementString());
getWidget().selectedOptionKey = suggestionKey;
}
}
@@ -296,8 +306,8 @@ public class ComboBoxConnector extends AbstractFieldConnector
private boolean isWidgetsCurrentSelectionTextInTextBox() {
return getWidget().currentSuggestion != null
- && getWidget().currentSuggestion.getReplacementString()
- .equals(getWidget().tb.getText());
+ && getWidget().currentSuggestion.getReplacementString().equals(
+ getWidget().tb.getText());
}
private void resetSelection() {
@@ -319,9 +329,18 @@ public class ComboBoxConnector extends AbstractFieldConnector
// just clear the input if the value has changed from something
// else to null
if (getWidget().selectedOptionKey != null
- || (getWidget().allowNewItem
- && !getWidget().tb.getValue().isEmpty())) {
+ || (getWidget().allowNewItem && !getWidget().tb
+ .getValue().isEmpty())) {
+
+ boolean openedPopupWithNonScrollingMode = (getWidget().popupOpenerClicked
+ && getWidget().getSelectedCaption() != null);
+ if (!openedPopupWithNonScrollingMode) {
getWidget().tb.setValue("");
+ } else {
+ getWidget().tb
+ .setValue(getWidget().getSelectedCaption());
+ getWidget().tb.selectAll();
+ }
}
}
getWidget().currentSuggestion = null; // #13217