summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasia Smirnova <anasmi@utu.fi>2018-09-06 16:25:07 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-09-06 16:25:07 +0300
commit78b1dc143983ddf25fae2cfda1c7705c2d40b2e4 (patch)
tree812acae2388bc301ddd7dea99b817e5c22c43a8b
parent99161a6e91ab0c40a14256393047ac426cc1c4e3 (diff)
downloadvaadin-framework-78b1dc143983ddf25fae2cfda1c7705c2d40b2e4.tar.gz
vaadin-framework-78b1dc143983ddf25fae2cfda1c7705c2d40b2e4.zip
Force re-updating the resolutions of DateField (#11159)
Fixes #11099
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractDateField.java1
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListener.java38
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListenerTest.java33
3 files changed, 72 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
index 5fdd3bb788..48bc3e13f5 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
@@ -520,6 +520,7 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster &
Integer defaultValuePart = getValuePart(defaultValue, resolution);
resolutions.put("default-" + resolutionName, defaultValuePart);
}
+ updateDiffstate("resolutions", Json.createObject());
}
private Integer getValuePart(T date, R resolution) {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListener.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListener.java
new file mode 100644
index 0000000000..e565f84b5a
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListener.java
@@ -0,0 +1,38 @@
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.DateField;
+
+import java.time.LocalDate;
+import java.util.Locale;
+
+public class DateFieldResetValueWithinListener extends AbstractTestUI {
+
+ public static LocalDate initialValue = LocalDate.of(2018, 8, 4);
+ public static LocalDate beforeInitialValue = LocalDate.of(2018, 7, 13);
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ LocalDate defaultDate = LocalDate.of(2018, 9, 4);
+ DateField df = new DateField("Date: ", defaultDate);
+ df.setDateFormat("d.M.yyyy");
+ df.setId("dateField1");
+ df.setValue(initialValue);
+ df.setLocale(Locale.ENGLISH);
+ df.addValueChangeListener(evt -> {
+ if (evt.getValue().isAfter(initialValue)) {
+ df.setValue(beforeInitialValue);
+ }
+ });
+
+ addComponent(df);
+ Button setV = new Button("Set date after the current", e -> {
+ LocalDate afterButtonPress = LocalDate.of(2018, 9, 12);
+ df.setValue(afterButtonPress);
+ });
+ setV.setId("setValueButton");
+ addComponent(setV);
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListenerTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListenerTest.java
new file mode 100644
index 0000000000..59a409d11f
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldResetValueWithinListenerTest.java
@@ -0,0 +1,33 @@
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+
+public class DateFieldResetValueWithinListenerTest extends MultiBrowserTest {
+
+ @Test
+ public void testValueReassigned() {
+ openTestURL();
+
+ DateTimeFormatter format = DateTimeFormatter.ofPattern("d.M.yyyy",
+ Locale.ENGLISH);
+ String textBefore = findElement(By.tagName("input"))
+ .getAttribute("value");
+ assertEquals(
+ DateFieldResetValueWithinListener.initialValue.format(format),
+ textBefore);
+
+ findElement(By.id("setValueButton")).click();
+
+ String textAfter = findElement(By.tagName("input"))
+ .getAttribute("value");
+ assertEquals(DateFieldResetValueWithinListener.beforeInitialValue
+ .format(format), textAfter);
+ }
+}