Vaadin DateField验证不显示验证错误 [英] Vaadin DateField validation does not show validation errors

查看:88
本文介绍了Vaadin DateField验证不显示验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用Vaadin 8,并且我尝试使用Vaadins DateField进行用户输入。

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);

DateValidator检查此人是否至少18岁。

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

问题是,如果我使用Datepicker,并且集成在DateField中,则如果Person不满18岁,则不会向用户显示验证错误。但是当我键入日期并按Enter或切换到另一个输入字段,将显示验证错误。

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.

如何通过Datepicker提供输入,如何显示验证错误?

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

推荐答案

显然, Validator 不能管理 ValueChange 事件。您可以这样自己完成操作:

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() ) );

还有一些示例 validate()函数:

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

这篇关于Vaadin DateField验证不显示验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆