Permalink
Browse files

Trigger change events for radio and checkbox items. Currently, no .on…

…('change'...) is fired if the model causes an update. This is necessary for widgets and listeners acting directly on the checkbox/radio items.

The change triggers must be deferred, however, or the old model value is actually thrown out to test units (and presumably public listeners).
  • Loading branch information...
1 parent 70fd0ab commit 5432d50e3d6cc8fc7fb7925aa636382c9a499dd5 @katowulf committed Apr 25, 2013
Showing with 8 additions and 0 deletions.
  1. +8 −0 Backbone.ModelBinder.js
View
@@ -407,17 +407,25 @@
switch (el.attr('type')) {
case 'radio':
if (el.val() === convertedValue) {
+ // must defer the change trigger or the change will actually fire with the old value
+ el.prop('checked') || _.defer(function() { el.trigger('change'); });
el.prop('checked', true);
}
else {
+ // must defer the change trigger or the change will actually fire with the old value
+ !el.prop('checked') || _.defer(function() { el.trigger('change'); });
el.prop('checked', false);
}
break;
case 'checkbox':
if (convertedValue) {
+ // must defer the change trigger or the change will actually fire with the old value
+ el.prop('checked') || _.defer(function() { el.trigger('change') });
el.prop('checked', true);
}
else {
+ // must defer the change trigger or the change will actually fire with the old value
+ el.prop('checked') || _.defer(function() { el.trigger('change') });
el.prop('checked', false);
}
break;

1 comment on commit 5432d50

Owner

katowulf commented on 5432d50 Apr 29, 2013

I committed this locally then realized it wasn't working in all browsers during testing. The next commit reverts and corrects this change.

Please sign in to comment.