Codename One - Validate only one input at a time

て烟熏妆下的殇ゞ 提交于 2019-12-08 08:17:54

问题


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

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/50249453/codename-one-validate-only-one-input-at-a-time

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