Skip to content

Commit

Permalink
fix: prevent initialValue from becoming emptyValue (#7030) (#7031)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Vinogradov <[email protected]>
  • Loading branch information
vaadin-bot and vursen authored Jan 13, 2025
1 parent ce1b925 commit dec84c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public DatePicker(LocalDate initialDate) {
* @see #setValue(Object)
*/
private DatePicker(LocalDate initialDate, boolean isInitialValueOptional) {
super("value", initialDate, String.class, PARSER, FORMATTER);
super("value", null, String.class, PARSER, FORMATTER);

// Initialize property value unless it has already been set from a
// template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public void setInitialValue() {
picker.getElement().getProperty("value"));
}

@Test
public void emptyValueIsNull() {
DatePicker picker = new DatePicker();
Assert.assertNull(picker.getEmptyValue());
}

@Test
public void setInitialValue_emptyValueIsNull() {
DatePicker picker = new DatePicker(LocalDate.of(2018, 4, 25));
Assert.assertNull(picker.getEmptyValue());
}

@Test
public void updatingToNullValue_displaysEmptyString() {
DatePicker picker = new DatePicker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public TimePicker(LocalTime time) {
* ignored and the initial value is set
*/
private TimePicker(LocalTime time, boolean isInitialValueOptional) {
super("value", time, String.class, PARSER, FORMATTER);
super("value", null, String.class, PARSER, FORMATTER);

// Initialize property value unless it has already been set from a
// template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public void timePicker_basicCases() {
assertEquals(LocalTime.of(7, 40), picker.getValue());
}

@Test
public void emptyValueIsNull() {
TimePicker picker = new TimePicker();
Assert.assertNull(picker.getEmptyValue());
}

@Test
public void setInitialValue_emptyValueIsNull() {
TimePicker picker = new TimePicker(LocalTime.of(5, 30));
Assert.assertNull(picker.getEmptyValue());
}

@Test
public void timePicker_nullValue() {
TimePicker timePicker = new TimePicker();
Expand Down

0 comments on commit dec84c9

Please sign in to comment.