2

I have a form that it repeated in a ng-repeat. I put part of my form in blow. for custom validation I want to use $setValidity in controller. But I cant to get input name by index in controller. How I use $scope.form.name1.$setValidity("size", false) and other input element?

<form name="form">
  <div ng-repeat="item in items track by $index">
      <input name='name{{$index}}' ng-model="name{{$index}}">
  </div>
 </form>

 function validation(index){
       if(...){
   $scope.form.name.$setValidity("size", false); // form.name0 and form.name1 and ...
       }
    }
Yogeshree Koyani
  • 1,649
  • 10
  • 19
Hadi J
  • 16,989
  • 4
  • 36
  • 62

1 Answers1

4

Bracket notation can be used.

$scope.form["name" + index].$setValidity("size", false);
Satpal
  • 132,252
  • 13
  • 159
  • 168