From 551177326f6ae8c4ddd7d5b3ab3bb3311304cc0a Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Fri, 19 Feb 2021 11:11:49 +0200 Subject: Add API to prevent invalid input when integrated range validator is used (#12168) Do not fire DateField's value change event if the new date is not within the range. Fixes: #12163 --- .../main/java/com/vaadin/ui/AbstractDateField.java | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index dbbc19b673..d14393c541 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -160,7 +160,14 @@ public abstract class AbstractDateField validator = getRangeValidator(); + ValidationResult result = validator.apply(newDate, + new ValueContext()); + if (!isPreventInvalidInput() || !result.isError()) { + setValue(newDate, true); + } else { + doSetValue(newDate); + } } } } @@ -229,6 +236,8 @@ public abstract class AbstractDateField