Binding true / false to radio buttons in Knockout JS

In this case, i think that a nice choice is to make the writeable computed evident a “sub-observable” of your IsActive discernible. Your view model would look like:

var ViewModel = function() {
 this.IsActive = ko.observable(true);

this.IsActive.ForEditing = ko.computed({
 read: function() {
 return this.IsActive().toString(); 
 write: function(newValue) {
 this.IsActive(newValue === "true");
 owner: this 

Bind in your html file like this:
 <input type="radio" name="IsActive" value="true" data-bind="checked:IsActive.ForEditing"/>
 <input type="radio" name="IsActive" value="false" data-bind="checked:IsActive.ForEditing"/>


Leave a Reply

Your email address will not be published. Required fields are marked *