代号一-一次仅验证一个输入 [英] Codename One - Validate only one input at a time

查看:51
本文介绍了代号一-一次仅验证一个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Validator类的一个问题是它验证添加了约束的所有输入(这意味着错误消息显示在尚未填充的输入或选定的选择器中):

A problem of the Validator class is that it validates all the inputs to which a constraint is added (that means that an error message is shown in not already filled inputs or selected pickers):

    Validator val = new Validator();
    val.addConstraint(title, new LengthConstraint(2));
    val.addConstraint(price, new NumericConstraint(true));

在此示例中,即使用户没有这样做,验证器也会显示标题和价格错误t还没有输入价格。

In this example, the validator will show an error for both title and price even if the user didn't entered a price yet.

更直观的是,只有在用户提供输入后才显示错误,这意味着仅显示价格错误

It would be more intuitive that an error is shown only after the user has given the input, that means to show an error for the price only after that a price is given.

我没有找到实现此行为的代码。

I didn't find a code to implement this behavior.

推荐答案

我的第一个想法是创建一个验证程序,该程序将检查是否已对某些内容进行修改并将其添加到验证链中。但是,这意味着如果您未输入所有内容,则输入内容可能有效。

My first thought was just create a validator which will check if something was modified and add it to the validation chain. However, that would mean the input could be valid if you didn't enter everything.

此功能应在此类的渲染逻辑中实现。在 Validator 本身中。您可以为此提交RFE或仅在拉取请求中实施。

This is a feature that should be implemented in the rendering logic for this class. In Validator itself. You can file an RFE for that or just implement it in a pull request.

这篇关于代号一-一次仅验证一个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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