Vaadin DateField validation does not show validation errors

故事扮演 提交于 2019-12-24 12:18:13

问题


Hello I'm using Vaadin 8 and im trying to use Vaadins DateField for user input.

private DateField date = new DateField("Date of Birth");
...
binder.forField(date).asRequired("Some Warning").withValidator(new DateValidator()).bind(Person::getDateOfBirth, Person::setDateOfBirth);

The DateValidator checks if the Person is at least 18 years old.

The Problem is that if I use the Datepicker, that is integrated in the DateField no validation error is shown to the user if the Person is younger than 18. But when I type in the date and hit enter or switch to another input field the validation error appears.

How can I achieve that the validation error is shown when the input is given via the Datepicker?


回答1:


Apparently Validator doesn't manage ValueChange event. You can do it on your own like this:

date.addValueChangeListener( event -> 
        validate( event.getSource().getDefaultValidator(), event.getValue() ) );

And some example validate() function:

private void validate(Validator validator, LocalDateTime dateTime)
{
    validator.apply(dateTime, ...);
}


来源:https://stackoverflow.com/questions/46604363/vaadin-datefield-validation-does-not-show-validation-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!