This is a migrated thread and some comments may be shown as answers.
Binding radio buttons - changed event?
0 Answers 233 Views
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 27 Mar 2012, 12:48 AM
Hi

I'm successfully binding a group of radio buttons to a ViewModel using a checked binding and also using the click event binding to refresh a Chart. It works wonderfully when the mouse is used to click the radio button as would be expected, but when the keyboard is used to change the selected radio button, things don't work as well: firstly, my click event handler still fires (much as it would if it were called "changed" or similar), the chart refreshes, but the value isn't updated by the checked binding. I thought perhaps the order of binding declarations in my markup mattered, but it makes no difference.

Markup:
<input id="activitiesThisMonth" value="A" type="radio" name="activitiesDuration" data-bind="checked: activitiesDuration, click: activitiesChanged" />
<label for="activitiesThisMonth">This Month</label>
<input id="activitiesThisWeek" value="W" type="radio" name="activitiesDuration" data-bind="checked: activitiesDuration, click: activitiesChanged" />
<label for="activitiesThisWeek">This Week</label>

Script:
var viewModel = kendo.observable({
    activitiesDuration: "W",
    activitiesChanged: function (e) {
        $("#activitiesChart").data("kendoChart").refresh();
    }
});
 
kendo.bind($("input"), viewModel);

Is this the expected behaviour? I there perhaps a workaround to achieve what I wish to do? I tried binding the jQuery change event to the radio buttons directly, but the event handler didn't fire at all when changed with the keyboard.

I look forward to a response, kind regards,
Andrew

No answers yet. Maybe you can help?

Tags
MVVM
Asked by
Andrew
Top achievements
Rank 1
Share this question
or