I have an array of objects with an observable property that is being bound to a group of radio buttons. The observable property can only have the following values ['Primary', 'Secondary', 'Occasional', 'none']
Here's the HTML.
<!--ko foreach: allDriversForPolicy-->
<div class="col-md-2">
<a href="#" class="thumbnail">
<div class="">
<label><input type="radio" value="Primary" data-bind="checked: vehicleDriverType, attr: {name: id}"/>Primary</label>
<label><input type="radio" value="Secondary" data-bind="checked: vehicleDriverType, attr: {name: id}" />Secondary</label>
<label><input type="radio" value="Ocasional" data-bind="checked: vehicleDriverType, attr: {name: id}" />Ocasional</label>
<label><input type="radio" value="" data-bind="checked: vehicleDriverType, attr: {name: id}" />None</label>
</div>
</a>
</div>
<!--/ko-->
And here is the JavaScript to get it running.
var SimpleListModel = function() {
this.allDriversForPolicy = ko.observableArray([
{'id': 'abe', 'vehicleDriverType': 'Primary'},
{'id': 'bob', 'vehicleDriverType': 'Secondary'},
{'id': 'charlie', 'vehicleDriverType': ''}
]);
};
ko.applyBindings(new SimpleListModel());
jsfiddle is here. The wrinkle I'm running into is an added requirement that out of all the objects there can only be one primary so I'd like the behaviour to be if Primary is selected then go through the array and switch any objects with the observable property set to 'Primary' to 'Secondary'.
How can I do this?