AngularJS表单验证指令$ setValidity元素 [英] AngularJS Form Validation Directive $setValidity on element
问题描述
我试图在指令中使用$ setValidity一个元素。我发现所有的例子似乎设置控制器上......
我在分叉表单验证一个JS小提琴和尝试了一堆东西。任何见解将是最AP preciated:
http://jsfiddle.net/thomporter/pmKpG/2/
在小提琴中,$ setValidity被称为控制器上:
CTRL $ setValidity('PWD',真)。
我想要做的是这样的:
榆树$ setValidity('PWD',真)。
这样的形式我可以这样做:
纳克级={错误:form.password $ error.pwd}
我想通了......你必须有输入元素的名称。当我添加的名称,错误被自动绑定到所希望的元素,没有其他更改需要!
<输入NG模型=密码NAME =控件inputPassword级=直接帮助密码验证所需类型=密码ID =控件inputPassword占位符= 密码>
http://jsfiddle.net/thomporter/pmKpG/4/
I'm trying to use $setValidity on an element in a directive. All the examples I've found seem to set it on the controller...
I forked a JS fiddle on Form Validation and have tried a bunch of things. Any insights would be most appreciated: http://jsfiddle.net/thomporter/pmKpG/2/
In the fiddle, the $setValidity is called on the controller:
ctrl.$setValidity('pwd', true);
I'd like to do something like:
elm.$setValidity('pwd', true);
so that in the form I can do something like:
ng-class="{error:form.password.$error.pwd}"
I figured it out... You have to have a name on the input elements. As soon as I added the name, the errors were automatically bound to the elements as desired, no additional changes needed!
<input ng-model="password" name="inputPassword" class="immediate-help" password-validate required type="password" id="inputPassword" placeholder="Password">
http://jsfiddle.net/thomporter/pmKpG/4/
这篇关于AngularJS表单验证指令$ setValidity元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!