1
votes

I would like to validate a form with multiple radio check boxes inside ng-repeat. How should I validate the selected option with radio button input:
Validation outside the ng-repeat works fine. For eg. when switching $index to customDish. The problem is validation inside ng-repeat with $index.

Field Required should be shown exactly to the selected radio button inside ng-repeat loop.

Here is a plunker

[http://plnkr.co/edit/j6bswtctD0ixaQmcDrp1?p=preview][1]

Please help
Thanks in advance

  [1]: http://plnkr.co/edit/j6bswtctD0ixaQmcDrp1?p=preview
2
Could you please write more clear? I cannot understand what you mean.Marcus
Select one of three radio buttons from top click submit required field is showing in all showuld show just to the selectedMichal Kucaj

2 Answers

1
votes

Just compare this with your's ng-show:

ng-show="submitClicked && myOrderForm.dishQuantity.$error.required && 
($parent.checkboxSelection == $index)"

I've added one more condition, ensuring, that error will show only for selected item.

0
votes

Another Solution

 <input ng-pattern="onlyNumbers" placeholder="quantity" ng-required="$parent.checkboxSelection === {{$index}}" name="dishQuantity{{$index}}" id="dishPrice" data-ng-model="dish.quantity" type="text" class="dish-quantity" id="dishQuantity" /> 

and span tag

<span class="custom-label-danger" ng-show="submitClicked && myOrderForm.dishQuantity{{$index}}.$error.required ">Field Required</span>

Also working :)