I make a simple form from object ..now i validate that form .I am facing few issues while validation.please check this on firefox..
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
<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
:
<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:
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.