In the example given below, I have used ng -repeat for dynamically creating input boxes. I have also used ng-form directive that allows the nesting of forms that can also be used for partial validation .
<form name="mainForm" ng-submit="submitAll()">
<ul>
<!-- We add ng-form to the tag ng-repeat is on,
to create a nested form context. -->
<li ng-repeat="item in items" ng-form="subForm">
<input type="text" required name="name" ng-model="item.name"/>
<!-- now we can reference the validated field by name -->
<span ng-show="subForm.name.$error.required">required</span>
<!-- the nested form context itself can also be checked for validity. -->
<button type="button" ng-disabled="subForm.$invalid"
ng-click="submitOne(item)">Submit One</button>
</li>
</ul>
<!-- last, but not least, the validation from our
subform bubbles up to our main form! -->
<button type="submit" ng-disabled="mainForm.$invalid">Submit All</button>
</form>
0 Comment(s)