javascript - form validation- validate inputs dynamically created by ng-repeat -


i'm trying form validation angular. able validate input elements follows,

<tr ng-repeat="answer in answers track $index" ng-form="subquestionform">     <td>         <div>             <div ng-class="{ 'has-error' :((subquestionform.anstext.$invalid && issubmitted) || ((subquestionform.anstext.$invalid && subquestionform.anstext.$dirty))}">                 <input name="anstext" id="anstext" type='text' ng-model="answer.anstext" class="form-control" required />                 <div class="error,help-block col-md-offset-4" ng-show="((subquestionform.lhstext.$dirty  || issubmitted) && ( subquestionform.lhstext.$invalid))">                     <h6 class="help-block" ng-if="subquestionform.lhstext.$error.required">enter  answer</h6>                 </div>             </div>         </div>     </td> </tr> 

this validate form such user has enter answer(i.e enter textbox created), want user should enter 2 or more . if 1 answer entered error message show otherwise form valid. tried doing taking index each failed. can throw light.

you can this:

<tr ng-repeat="answer in answers track $index" ng-form="subquestionform">     <td>        <div>         <input name="anstext" id="anstext" type='text' ng-model="answer.anstext" class="form-control" ng-required="$index == 0 || $index == 1 " />             </div>         </td> </tr> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -