[英]validation issue using angular js (red border display on firefox)?
I make a simple form from object ..now i validate that form .I am facing few issues while validation.please check this on firefox.. 我从对象创建一个简单的表单..现在我验证该表单.validation时遇到几个问题。请在Firefox上进行检查。
http://plnkr.co/edit/CFUR2mgVv4hzXPF7AR9y?p=preview http://plnkr.co/edit/CFUR2mgVv4hzXPF7AR9y?p=preview
I study lot of tutorial but I apply this thing $dirty , $pristine but nothing works for me.. I study from there validation .. http://scotch.io/tutorials/javascript/angularjs-form-validation 我研究了很多教程,但是我应用了$ dirty,$ pristine这个东西,但是对我没有用。.我从那里学习验证.. http://scotch.io/tutorials/javascript/angularjs-form-validation
<ul ng-repeat="input in inputs">
<li><span>{{input.name}} : </span>
<div ng-switch="input.type" ng-form="myfrm">
<div ng-switch-when="text">
<input type="text" ng-model="outputs[input.name]"/>
</div>
<div ng-switch-when="email" class="form-group" >
<input type="email" ng-model="outputs[input.name]" name="input" ng-required="input.required">
<P ng-show="myfrm.input.$invalid && !myform.input.$pristine">Please enter a valid email</P>
</div>
<div ng-switch-when="number">
<input type="number" ng-model="outputs[input.name]" ng-required="input.required" name="input"/>
<P ng-if="myfrm.input.$invalid">Please enter a valid number</P>
</div>
<div ng-switch-when="url">
<input type="number" ng-model="outputs[input.name]"/>
</div>
<div ng-switch-when="checkbox">
<input type="checkbox" ng-model="outputs[input.name]" ng-checked="outputs[input.name]" value="outputs[input.name]"/>
</div>
</div>
</li>
</ul>
There is a typo where you use $pristine
, the myform
should be myfrm
like you set in ng-form
: 在使用$pristine
有一个错字,就像在ng-form
设置的那样, myform
应该是myfrm
:
<p ng-show="myfrm.input.$invalid && !myfrm.input.$pristine">Please enter a valid email</p>
To show different messages for invalid email and empty email, you could use $error
instead of $invalid
like this: 要为无效电子邮件和空电子邮件显示不同的消息,可以使用$error
代替$invalid
如下所示:
<p ng-show="myfrm.input.$error.email && !myfrm.input.$pristine">Please enter a valid email</p>
<p ng-show="myfrm.input.$error.required && !myfrm.input.$pristine">Please enter the email</p>
Example Plunker: http://plnkr.co/edit/eD4OZ8nqETBACpSMQ7Tm?p=preview Plunker示例: http ://plnkr.co/edit/eD4OZ8nqETBACpSMQ7Tm?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.