From 257792423bcdb9b80184305b02685deac2b6b467 Mon Sep 17 00:00:00 2001 From: Sergey Vinogradov Date: Wed, 16 Mar 2022 18:08:39 +0300 Subject: [PATCH] fix: ensure DatePicker initializes value property --- .../java/com/vaadin/flow/component/datepicker/DatePicker.java | 4 ++++ .../com/vaadin/flow/component/datepicker/DatePickerTest.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/main/java/com/vaadin/flow/component/datepicker/DatePicker.java b/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/main/java/com/vaadin/flow/component/datepicker/DatePicker.java index cbdb002d558..72cb49eead5 100644 --- a/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/main/java/com/vaadin/flow/component/datepicker/DatePicker.java +++ b/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/main/java/com/vaadin/flow/component/datepicker/DatePicker.java @@ -83,6 +83,10 @@ public class DatePicker extends GeneratedVaadinDatePicker */ public DatePicker() { this((LocalDate) null, true); + // Trigger model-to-presentation conversion in constructor, so that + // the client side component has a correct initial value of an empty + // string + this.setPresentationValue(null); } /** diff --git a/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/test/java/com/vaadin/flow/component/datepicker/DatePickerTest.java b/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/test/java/com/vaadin/flow/component/datepicker/DatePickerTest.java index 55847081ad8..60fed87c727 100644 --- a/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/test/java/com/vaadin/flow/component/datepicker/DatePickerTest.java +++ b/vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/test/java/com/vaadin/flow/component/datepicker/DatePickerTest.java @@ -54,7 +54,7 @@ public void datePicker_basicCases() { DatePicker picker = new DatePicker(); Assert.assertNull(picker.getValue()); - Assert.assertFalse(picker.getElement().hasProperty("value")); + Assert.assertEquals("", picker.getElement().getProperty("value")); picker.setValue(LocalDate.of(2018, 4, 25)); Assert.assertEquals("2018-04-25", @@ -73,7 +73,7 @@ public void datePicker_basicCases() { public void defaultCtor_does_not_update_values() { DatePicker picker = new DatePicker(); Assert.assertNull(picker.getValue()); - Assert.assertNull(picker.getElement().getProperty("value")); + Assert.assertEquals("", picker.getElement().getProperty("value")); } @Test