diff options
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/AbstractDateField.java')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/AbstractDateField.java | 35 |
1 files changed, 34 insertions, 1 deletions
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<T extends Temporal & TemporalAdjuster & } } } else { - setValue(newDate, true); + RangeValidator<T> 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<T extends Temporal & TemporalAdjuster & private String dateOutOfRangeMessage = "Date is out of allowed range"; + private boolean preventInvalidInput = false; + /* Constructors */ /** @@ -1130,4 +1139,28 @@ public abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & public void getAssistiveLabel(AccessibleElement element) { getState(false).assistiveLabels.get(element); } + + /** + * Control whether value change event is emitted when user input value + * does not meet the integrated range validator. + * + * @param preventInvalidInput Set to false to disable the value change event. + * + * @since 8.13 + */ + public void setPreventInvalidInput(boolean preventInvalidInput) { + this.preventInvalidInput = preventInvalidInput; + } + + /** + * Check whether value change is emitted when user input value does + * not meet integrated range validator. The default is false. + * + * @return a Boolean value + * + * @since 8.13 + */ + public boolean isPreventInvalidInput() { + return preventInvalidInput; + } } |