2017-12-30 53 views
1

私はIonicを使用していますが、複数のフォームに対してng-repeatを使用しています。私はフォームごとに別々のバリデーションをしたいと思いますが、どのように私がこの作業をすることができるか分かりません。別々のフォームのためのng-repeatでの個別検証

<div class="form-errors" 
     ng-show="testForm[question.QuestionId].$error.required" 
     ng-messages="testForm[question.QuestionId].$error" 
     ng-messages-include="shared/form-errors.html" 
     ng-if="question.QuestionType == 'QuestionRadio'"> 
</div> 

検証作業を行うための機能ではなく:

コード:

<ion-list ng-if="question.QuestionType == 'QuestionRadio'"> 
    <ion-radio ng-repeat="choice in question.Answers" 
       ng-model="vm.answer[choice.AnswerId]" 
       name="{{question.QuestionId}}" 
       ng-required="vm.answer" 
       ng-required="!vm.someSelected(vm.answer)"> 
     {{choice.Text}} 
    </ion-radio> 
</ion-list> 

エラーメッセージを表示するためのコードを組み合わせる

vm.someSelected = function (object) { 
      return Object.keys(object).some(function (key) { 
      return object[key]; 
      }); 
     } 

上記のコードはフォームにバリデーションを行いますが、1つのフォームが合格すると、それらのすべてが渡されます悲しい結果。フォームに検証を渡す独自の方法があるように、どうすればよいですか?要素の

答えて

1

重複する属性は無視されます。

<ion-list ng-if="question.QuestionType == 'QuestionRadio'"> 
    <ion-radio ng-repeat="choice in question.Answers" 
       ng-model="vm.answer[choice.AnswerId]" 
       name="{{question.QuestionId}}" 
       ̶n̶g̶-̶r̶e̶q̶u̶i̶r̶e̶d̶=̶"̶v̶m̶.̶a̶n̶s̶w̶e̶r̶"̶ 
       ̶n̶g̶-̶r̶e̶q̶u̶i̶r̶e̶d̶=̶"̶!̶v̶m̶.̶s̶o̶m̶e̶S̶e̶l̶e̶c̶t̶e̶d̶(̶v̶m̶.̶a̶n̶s̶w̶e̶r̶)̶"̶ 
       ng-required="vm.answer[choice.AnswerId] && !vm.someSelected(vm.answer)"> 
     {{choice.Text}} 
    </ion-radio> 
</ion-list> 
関連する問題