I'm looking to create a variant of the 'checked' binding handler, for a specific case in our app. I'm still puzzling over how to approach editing a version based off Knockout's 'checked' binding...
Ultimately, I need to have the radio button set a value to true or false, depending on if it's selected. The existing implementation is set to only update on the 'click' event - it doesn't fire an event for the deselection. (Which makes sense, for all other usages)
So in the app/use-case:
- I have a variable list of items, of which only one can be selected (managed by radio buttons)
- The viewmodel for each row contains a bool property - e.g.: 'isSelected'
This looks like it's defending against the 'deselection' event - though it never gets fired anyway..
function updateModel() {
[...]
// We can ignore unchecked radio buttons, because some other radio
// button will be getting checked, and that one can take care of updating state.
if (isRadio && !isChecked) {
return;
}
Here I'm wondering if I need to change the event handler registration to something broader than 'click', though I'm not yet sure.
function updateView() {
[...]
ko.utils.registerEventHandler(element, "click", updateModel);
Any input on how to approach this style of modified checked binding / radio button usage would be appreciated.