I'm trying to get AngularJS to repeated sets of the same type of input radio fields.
Example:
<form>
<ul id="group1">
<li><input type='radio' name='optionRadio'></li>
<li><input type='radio' name='optionRadio'></li>
</ul>
<ul id="group2">
<li><input type='radio' name='optionRadio'></li>
<li><input type='radio' name='optionRadio'></li>
</ul>
</form>
AngularJS I have:
<form name='testForm'>
<ul ng-repeat='field in fields' ng-form='subForm'>
<li><input type='radio' ng-model='subForm.optionRadio' name='optionRadio'>field.name</li>
</ul>
</form>
The problem is when I click the radio button, it will deselect the the radio in another group.
I know the issue is name = optionRadio, but I'm trying to take advantage of $invalid from the form testForm.
If I remove name='optionRadio', I loose track of which form item needs to be highlighted for errors.
I also tried doing separate form tags, but I was having troubles with ng-repeat and form tags.
I also tried appending $index to the name, but the form object takes in the value literally.
Any suggestions on how to do this properly would be much appreciated.
EDIT: http://jsfiddle.net/HB7LU/207/
I've made a jsfiddle. I found a solution, that will work, but won't make use of the form validation.
I can get the same result of having an error message, by checking if the model has a value. The other option is to write a custom directive for validation, then check the sub form for the specific error I'm looking for.
Example:
<input radioCheck type='radio' name='optionRadio'/>
<span ng-show='subForm.$error.radioCheck'>Radio check error</span>