summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-06-05 15:06:25 +0300
committerGitHub <noreply@github.com>2017-06-05 15:06:25 +0300
commit3b3c647e5b732a7e9e6109193a11e665270ffe2f (patch)
tree3e1b435ff965ba45ccbb5a3408c8e8eb4ecd6e2c /client
parentbdb81a11c6deb76638a3e1f82f123d94744295a7 (diff)
downloadvaadin-framework-3b3c647e5b732a7e9e6109193a11e665270ffe2f.tar.gz
vaadin-framework-3b3c647e5b732a7e9e6109193a11e665270ffe2f.zip
Show empty selection caption in ComboBox (#9468)
Fixes #9079
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VComboBox.java35
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java4
2 files changed, 33 insertions, 6 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
index 2a76907170..787d82caec 100644
--- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java
+++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
@@ -243,12 +243,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
return $entry(function(e) {
var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX;
var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY;
-
+
// IE8 has only delta y
if (isNaN(deltaY)) {
deltaY = -0.5*e.wheelDelta;
}
-
+
@com.vaadin.client.ui.VComboBox.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode);
});
}-*/;
@@ -1669,6 +1669,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
* field even for filtering.
*/
private boolean textInputEnabled = true;
+ private String emptySelectionCaption = "";
private final DataReceivedHandler dataReceivedHandler = new DataReceivedHandler();
@@ -1949,7 +1950,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
dataReceivedHandler.cancelPendingPostFiltering();
currentSuggestion = null;
- setText("");
+ setText(getEmptySelectionCaption());
setSelectedItemIcon(null);
if (!"".equals(selectedOptionKey) || selectedOptionKey != null) {
@@ -1958,6 +1959,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
connector.sendSelection(null);
// currentPage = 0;
}
+
updatePlaceholder();
suggestionPopup.hide();
@@ -2028,7 +2030,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
if (selectedKey == null || "".equals(selectedKey)) {
currentSuggestion = null; // #13217
selectedOptionKey = null;
- setText("");
+ setText(getEmptySelectionCaption());
}
// some item selected
for (ComboBoxSuggestion suggestion : currentSuggestions) {
@@ -2305,7 +2307,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
// just fetch selected information from state
String text = connector.getState().selectedItemCaption;
- setText(text == null ? "" : text);
+ setText(text == null ? getEmptySelectionCaption() : text);
setSelectedItemIcon(connector.getState().selectedItemIcon);
selectedOptionKey = (connector.getState().selectedItemKey);
if (selectedOptionKey == null || "".equals(selectedOptionKey)) {
@@ -2820,4 +2822,27 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
public boolean getNullSelectionItemShouldBeVisible() {
return nullSelectionAllowed && "".equals(lastFilter);
}
+
+ /**
+ * Gets the empty selection caption.
+ *
+ * @return the empty selection caption
+ */
+ public String getEmptySelectionCaption() {
+ return emptySelectionCaption;
+ }
+
+ /**
+ * Sets the empty selection caption for this VComboBox. The text is
+ * displayed in the text input when nothing is selected.
+ *
+ * @param emptySelectionCaption
+ * the empty selection caption
+ */
+ public void setEmptySelectionCaption(String emptySelectionCaption) {
+ this.emptySelectionCaption = emptySelectionCaption;
+ if (selectedOptionKey == null) {
+ setText(emptySelectionCaption);
+ }
+ }
}
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 7fec2ae8e0..9d37afc8a5 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
@@ -105,9 +105,11 @@ public class ComboBoxConnector extends AbstractListingConnector
suggestions.remove(0);
addEmptySelectionItem();
}
+ getWidget().setEmptySelectionCaption(getState().emptySelectionCaption);
}
- @OnStateChange({ "selectedItemKey", "selectedItemCaption", "selectedItemIcon" })
+ @OnStateChange({ "selectedItemKey", "selectedItemCaption",
+ "selectedItemIcon" })
private void onSelectionChange() {
getDataReceivedHandler().updateSelectionFromServer(
getState().selectedItemKey, getState().selectedItemCaption,