I have an AngularJS app which asks the user to input a number from some options using a radio button group to indicate their choice.
There are 3 fixed options (with values 1, 2 and 3 for example), and a fourth option which contains a select list with the additional option values 4, 5, 6. The fixed values are common enough to separate them but we want to be able to give alternate options.
Everything is fine without the select list as the 4th option, but I am having trouble with handling the 2 separate values for the radio button value and the value of the select list.
Ideally, the markup for this situation is something like
<!-- Controller aliased as ctrl-->
<!-- Fixed Option 1-->
<label>
<input type="radio" name="selectedNumber" ng-model="ctrl.SelectedNumber" ng-value="1"/>
1
</label>
<!-- Fixed Option 2-->
<label>
<input type="radio" name="selectedNumber" ng-model="ctrl.SelectedNumber" ng-value="2"/>
2
</label>
<!-- Fixed Option 3-->
<label>
<input type="radio" name="selectedNumber" ng-model="ctrl.SelectedNumber" ng-value="3"/>
3
</label>
<!-- Custom Option-->
<label>
<input type="radio" name="selectedNumber" ng-model="ctrl.SelectedNumber" ng-value="?"/>
<select ng-model="ctrl.SelectedNumber" ng-options="option for option in [4, 5, 6]"></select>
</label>
With a controller that looks like
...
var ctrl = this;
ctrl.SelectedNumber = 1;
...
My question is this: how can I keep track of the state of the radio button group and the state of the select list to bind to a single selected option?
A jsFiddle can be found here. Thank you!