diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-01-28 12:34:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 12:34:22 +0200 |
commit | 75caa0488dee5b59f37d5691430c01de0b55c2db (patch) | |
tree | a58c3fb8fb1fa29a80d97ce982ac3acb6a78a0f5 /client | |
parent | 2aa2de52f0c532f4a6f400b16eb08c340fc80f02 (diff) | |
download | vaadin-framework-75caa0488dee5b59f37d5691430c01de0b55c2db.tar.gz vaadin-framework-75caa0488dee5b59f37d5691430c01de0b55c2db.zip |
Don't reset date to current at DateField state (e.g. read-only) updates. (#11879)
- DateFields with month or year resolution should not get their date
reset to current date if the field's state is updated (e.g. by changing
read-only status or adding a range).
Fixes: #11864, #11605
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java index c049a25a53..8fde0264e4 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractCalendarPanel.java @@ -16,6 +16,8 @@ package com.vaadin.client.ui; +import static com.vaadin.client.DateTimeService.asTwoDigits; + import java.util.Date; import java.util.HashMap; import java.util.List; @@ -30,7 +32,6 @@ import com.google.gwt.aria.client.Roles; import com.google.gwt.aria.client.SelectedValue; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Style; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; import com.google.gwt.event.dom.client.ClickHandler; @@ -56,14 +57,11 @@ import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.InlineHTML; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.BrowserInfo; import com.vaadin.client.DateTimeService; import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.shared.util.SharedUtil; -import static com.vaadin.client.DateTimeService.asTwoDigits; - /** * Abstract calendar panel to show and select a date using a resolution. The * class is parameterized by the date resolution enumeration type. @@ -963,7 +961,17 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> * resolution of the calendar is changed and no date has been * selected. */ + @SuppressWarnings("rawtypes") public void renderCalendar(boolean updateDate) { + if (parent instanceof VAbstractPopupCalendar + && !((VAbstractPopupCalendar) parent).popup.isShowing()) { + if (getDate() == null) { + // no date set, cannot pre-render yet + return; + } + // a popup that isn't open cannot possibly need a focus change event + updateDate = false; + } doRenderCalendar(updateDate); initialRenderDone = true; @@ -986,11 +994,15 @@ public abstract class VAbstractCalendarPanel<R extends Enum<R>> getDateField().getStylePrimaryName() + "-calendarpanel"); if (focusedDate == null) { - Date now = new Date(); + Date date = getDate(); + if (date == null) { + date = new Date(); + } // focusedDate must have zero hours, mins, secs, millisecs - focusedDate = new FocusedDate(now.getYear(), now.getMonth(), - now.getDate()); - displayedMonth = new FocusedDate(now.getYear(), now.getMonth(), 1); + focusedDate = new FocusedDate(date.getYear(), date.getMonth(), + date.getDate()); + displayedMonth = new FocusedDate(date.getYear(), date.getMonth(), + 1); } if (updateDate && !isDay(getResolution()) |