Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 5432d50e3d6cc8fc7fb7925aa636382c9a499dd5 1 parent 70fd0ab
@katowulf authored
Showing with 8 additions and 0 deletions.
  1. +8 −0 Backbone.ModelBinder.js
View
8 Backbone.ModelBinder.js
@@ -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

@katowulf
Owner

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.
Something went wrong with that request. Please try again.