简体   繁体   English

在Aurelia中动态添加验证

[英]Add Validation in Aurelia dynamically

Is there a way to add Validation to a property on my VM "dynamically" (ie sometime after I register the initial rules on the VM)? 是否可以“动态”(即在我在VM上注册初始规则后的某个时间)将验证添加到VM上的属性?

Currently, I'm registering the rules in the constructor of the VM, then a little while later, after the user has entered a bunch of data, I need to show a new field (using if.bind) and want to add validation depending on the result of a web api call.. 目前,我正在VM的构造函数中注册规则,然后过一会儿,在用户输入一堆数据之后,我需要显示一个新字段(使用if.bind),并希望添加验证通过网络api调用的结果。

Wondering if there's an API for this that I've missed? 想知道我是否缺少为此提供的API?

You can achieve it without dynamically adding rule but instead you can use satisfiesRule and when , see it here in section Conditional Validation. 你可以实现它没有动态地添加规则,而是你可以使用satisfiesRulewhen ,看到这里的部分条件验证。 satisfiesRule will only evaluated if the property that attached to it is already pass. satisfiesRule仅在附加给它的属性已经通过的情况下才进行评估。 when will only evaluated the rule if the condition is true. when仅在条件为true时才评估规则。

Additional link. 附加链接。 If you're using bootstrap, you can find this useful . 如果您使用的是引导程序,则可以找到有用的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM