From: Tatu Lund Date: Wed, 8 Apr 2020 09:17:11 +0000 (+0300) Subject: Set DateField value only if it passes range check (#11887) X-Git-Tag: 8.11.0.alpha1~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a486f6480979e93812cb1236e89e41d03f79d448;p=vaadin-framework.git Set DateField value only if it passes range check (#11887) Fixes #11108 --- diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index c252655e44..9c5d9bb656 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -297,7 +297,10 @@ public abstract class AbstractDateField - * Note: Negative, i.e. BC dates are not supported + * Note: Negative, i.e. BC dates are not supported. + *

+ * Note: It's usually recommended to use only one of the following at the same + * time: Range validator with Binder or DateField's setRangeStart check. * * @param startDate * - the allowed range's start date @@ -359,6 +362,9 @@ public abstract class AbstractDateField + * Note: It's usually recommended to use only one of the following at the same + * time: Range validator with Binder or DateField's setRangeEnd check. * * @param endDate * the allowed range's end date (inclusive, based on the current @@ -618,27 +624,38 @@ public abstract class AbstractDateField validator = getRangeValidator(); + ValidationResult result = validator.apply(value, + new ValueContext(this, this)); + + if (result.isError()) { + throw new IllegalArgumentException( + "value is not within acceptable range"); + } else { + currentErrorMessage = null; /* - * Side-effects of doSetValue clears possible previous strings and - * flags about invalid input. + * First handle special case when the client side component has a date + * string but value is null (e.g. unparsable date string typed in by the + * user). No value changes should happen, but we need to do some + * internal housekeeping. */ - doSetValue(null); - - markAsDirty(); - return; + if (value == null && !getState(false).parsable) { + /* + * Side-effects of doSetValue clears possible previous strings and + * flags about invalid input. + */ + doSetValue(null); + + markAsDirty(); + return; + } + super.setValue(value); } - super.setValue(value); } /** @@ -785,8 +802,8 @@ public abstract class AbstractDateField