I'm trying to add a variable Writable computed observables to an object, I use it to add radio buttons to each row of a table with Knockout, I have this:
JS
var PageBackControls = {
ApplyRecommended: ko.observable(true)
/*Resto del objeto*/
}
PageBackControls.AgregarBotones = ko.computed({
read: function () {
return PageBackControls.ApplyRecommended().toString();
},
write: function (newValue) {
PageBackControls.ApplyRecommended(newValue === "true");
},
owner: this
});
HTML
<div class="roundedRadio">
<input type="radio" data-bind="attr: { 'id': 'radio1-' + ControlID(), 'name': 'buton1-' + ControlID(), value: 'true' }, checked: PageBackControls.AgregarBotones" />
<label data-bind="attr: { 'for': 'radio1-' + ControlID() }"></label>
</div>
<div class="col-xs-1">
<label>Yes</label>
</div>
<div class="roundedRadio">
<input type="radio" data-bind="attr: { 'id': 'radio2-' + ControlID(),'name': 'buton1-' + ControlID(), value: 'false' }, checked: PageBackControls.AgregarBotones" />
<label data-bind="attr: { 'for': 'radio2-' + ControlID() }"></label>
</div>
<div class="col-xs-1">
<label>No</label>
</div>
But when executing the code when selecting a radiobutton all are changed at the same time and not as individual buttons, any error that you see in my code?