Search code examples
javascriptmvvmkendo-uikendo-mvvm

How to reset a Kendo MVVM Radio Button's checked state?


In Kendo MVVM, I keep track of a radio button groups' selected state. At some point I would like to reset the radio buttons for a group to become unchecked. I tried the following and it does not seem to work:

  1. Create input:
<input type="radio" value="1" data-bind="checked: selectedRadio1"/>
  1. Make view model object
var viewModel = kendo.observable({
  selectedRadio1: null
};
kendo.bind(document.body, viewModel);
  1. Set the value, by clicking on a radio option (selectedRadio1 has value).

  2. Reset the value

viewModel.set('selectedRadio1', null);

The reset doesn't work because the value null does not exist as radio button value. How do you get it to properly reset? Is data-bind="checked: ..." the right approach?

Kendo dojo link here: http://dojo.telerik.com/AgAxo


Solution

  • As you said there is no radio button with value "null", therefor observable object won't find any suitable DOM to move the checked property.. Until the developer of observable rewrite how checked property work with null value, you could use jquery or javascript code for this

    check this dojo