I'm using Ionic and I'm using ng-repeat for multiple forms. I'd like to have separate validation for each form, but I'm not sure how I could make this work.
The code:
<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>
The code to show error message:
<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>
The function to make validation work, but not for separate forms:
vm.someSelected = function (object) {
return Object.keys(object).some(function (key) {
return object[key];
});
}
Combining the code above will make the form have validation, but if one form passes, all of them will pass, which is an undesired result. How do I make it so a form has a unique way of passing validation?