diff options
author | Guillermo Alvarez <guillermo@vaadin.com> | 2014-09-05 14:07:49 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-09-09 11:51:57 +0000 |
commit | ca2c0a91bcec3410958ec2ae79366a42b248b311 (patch) | |
tree | 97c0a25870bffb748d6444c84efced778eec2e70 /server/src/com/vaadin/ui/DateField.java | |
parent | 986ba87d32ebaa52dd2a87d8c6fa02d9eb873f61 (diff) | |
download | vaadin-framework-ca2c0a91bcec3410958ec2ae79366a42b248b311.tar.gz vaadin-framework-ca2c0a91bcec3410958ec2ae79366a42b248b311.zip |
DateField ValueChange is now fired after flags are set (#14487)
When the UI had an invalid string the ValueChange event was fired
before setting all the flags causing an invalid isValid result when
handling ValueChange. Now the event is fired after the flags are set.
Change-Id: Ie4e6ba21edc81bf41c2c661aa27e0ace71e1bef0
Diffstat (limited to 'server/src/com/vaadin/ui/DateField.java')
-rw-r--r-- | server/src/com/vaadin/ui/DateField.java | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index e98b1e1b31..ba1178548f 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -153,6 +153,13 @@ public class DateField extends AbstractField<Date> implements private DateRangeValidator currentRangeValidator; + /** + * Determines whether the ValueChangeEvent should be fired. Used to prevent + * firing the event when UI has invalid string until uiHasValidDateString + * flag is set + */ + private boolean preventValueChangeEvent = false; + static { variableNameForResolution.put(Resolution.SECOND, "sec"); variableNameForResolution.put(Resolution.MINUTE, "min"); @@ -543,13 +550,21 @@ public class DateField extends AbstractField<Date> implements /* * Datefield now contains some text that could't be parsed - * into date. + * into date. ValueChangeEvent is fired after the value is + * changed and the flags are set */ if (oldDate != null) { /* - * Set the logic value to null. + * Set the logic value to null without firing the + * ValueChangeEvent */ - setValue(null); + preventValueChangeEvent = true; + try { + setValue(null); + } finally { + preventValueChangeEvent = false; + } + /* * Reset the dateString (overridden to null by setValue) */ @@ -571,6 +586,13 @@ public class DateField extends AbstractField<Date> implements uiHasValidDateString = false; /* + * If value was changed fire the ValueChangeEvent + */ + if (oldDate != null) { + fireValueChange(false); + } + + /* * Because of our custom implementation of isValid(), that * also checks the parsingSucceeded flag, we must also * notify the form (if this is used in one) that the @@ -603,6 +625,16 @@ public class DateField extends AbstractField<Date> implements } } + /* + * only fires the event if preventValueChangeEvent flag is false + */ + @Override + protected void fireValueChange(boolean repaintIsNotNeeded) { + if (!preventValueChangeEvent) { + super.fireValueChange(repaintIsNotNeeded); + } + } + /** * This method is called to handle a non-empty date string from the client * if the client could not parse it as a Date. |