summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorSun Zhe <31067185+ZheSun88@users.noreply.github.com>2019-04-24 13:28:01 +0300
committerGitHub <noreply@github.com>2019-04-24 13:28:01 +0300
commitd3eb272d7be8ef8f2ceca1b9fc85f2adf5c564ea (patch)
tree67602b4575c52c4c4299d5469e54646f3fabc54b /client
parente788dae27aaf99f8a6956dcde6eb95f2d1d5c38f (diff)
downloadvaadin-framework-d3eb272d7be8ef8f2ceca1b9fc85f2adf5c564ea.tar.gz
vaadin-framework-d3eb272d7be8ef8f2ceca1b9fc85f2adf5c564ea.zip
Reset Combobox internal state (#11412)
issue in #11343 and #11385 is not reproducible on top this patch Three different bugs are involved in this fix: we bring the old fix(#11094) back and fixed the other related issues: 1) allow adding the same new item after dataProvider got reset, This is cause by the client side parameter `LastNewItemString`, it saves the value added before resetting. 2) clear the pending newItem eagerly, so that the same value will not be added again.
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VComboBox.java38
-rw-r--r--client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java22
2 files changed, 44 insertions, 16 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 fbac85c2af..50d4c6588c 100644
--- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java
+++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
@@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
-import java.util.UUID;
import java.util.logging.Logger;
import com.google.gwt.animation.client.AnimationScheduler;
@@ -122,7 +121,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
* icon URI or null
*/
public ComboBoxSuggestion(String key, String caption, String style,
- String untranslatedIconUri) {
+ String untranslatedIconUri) {
this.key = key;
this.caption = caption;
this.style = style;
@@ -1642,6 +1641,11 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
performSelection(selectedKey, oldSuggestionTextMatchTheOldSelection,
!isWaitingForFilteringResponse() || popupOpenerClicked);
+ // currentSuggestion should be set to match the value of the
+ // ComboBox
+ resetCurrentSuggestionBasedOnServerResponse(selectedKey,
+ selectedCaption, selectedIconUri);
+
cancelPendingPostFiltering();
setSelectedCaption(selectedCaption);
@@ -1649,6 +1653,22 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
setSelectedItemIcon(selectedIconUri);
}
+ /*
+ * Updates the current suggestion based on values provided by the
+ * server.
+ */
+ private void resetCurrentSuggestionBasedOnServerResponse(
+ String selectedKey, String selectedCaption,
+ String selectedIconUri) {
+ if (currentSuggestion == null
+ && (selectedKey != null || selectedCaption != null)) {
+ currentSuggestion = new ComboBoxSuggestion(selectedKey,
+ selectedCaption, "", selectedIconUri);
+ } else if (selectedKey == null && selectedCaption == null) {
+ currentSuggestion = null;
+ }
+ }
+
}
// TODO decide whether this should change - affects themes and v7
@@ -1707,7 +1727,9 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
/** For internal use only. May be removed or replaced in the future. */
public boolean initDone = false;
- /** For internal use only. May be removed or replaced in the future. */
+ /**
+ * For internal use only. May be removed or replaced in the future.
+ */
public String lastFilter = "";
/**
@@ -1802,6 +1824,16 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
return s.getMarginWidth() + s.getBorderWidth() + s.getPaddingWidth();
}
+ /**
+ * This method will reset the saved item string which is added last time.
+ */
+ public void resetLastNewItemString() {
+ // Clean the temp string eagerly in order to re-add the same value again
+ // after data provider got reset.
+ // Fixes issue https://github.com/vaadin/framework/issues/11317
+ lastNewItemString = null;
+ }
+
/*
* (non-Javadoc)
*
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 3aa58083cf..2ef091569d 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
@@ -130,11 +130,9 @@ public class ComboBoxConnector extends AbstractListingConnector
getWidget().selectedOptionKey = null;
getWidget().currentSuggestion = null;
}
- if (isNewItemStillPending()
- && pendingNewItemValue == getState().selectedItemCaption) {
- // no automated selection handling required
- clearNewItemHandling();
- }
+
+ clearNewItemHandlingIfMatch(getState().selectedItemCaption);
+
getDataReceivedHandler().updateSelectionFromServer(
getState().selectedItemKey, getState().selectedItemCaption,
getState().selectedItemIcon);
@@ -188,10 +186,11 @@ public class ComboBoxConnector extends AbstractListingConnector
if (itemValue != null && !itemValue.equals(pendingNewItemValue)) {
// clear any previous handling as outdated
clearNewItemHandling();
+
+ pendingNewItemValue = itemValue;
+ rpc.createNewItem(itemValue);
+ getDataReceivedHandler().clearPendingNavigation();
}
- pendingNewItemValue = itemValue;
- rpc.createNewItem(itemValue);
- getDataReceivedHandler().clearPendingNavigation();
}
/**
@@ -359,7 +358,7 @@ public class ComboBoxConnector extends AbstractListingConnector
updateSuggestions(start, end);
getWidget().setTotalSuggestions(getDataSource().size());
-
+ getWidget().resetLastNewItemString();
getDataReceivedHandler().dataReceived();
}
@@ -451,10 +450,7 @@ public class ComboBoxConnector extends AbstractListingConnector
* versions.
*/
private void clearNewItemHandling() {
- // never clear pending value before it has been handled
- if (!isNewItemStillPending()) {
- pendingNewItemValue = null;
- }
+ pendingNewItemValue = null;
}
/**