Permalink
Browse files

Fixed bug where a[disable-with] got set to blank html when ajax retur…

…ned error, due to enableElement being triggered twice.
  • Loading branch information...
1 parent 049d203 commit 610dfb8881377598b7e63ab2c152d73aa1d3632f @JangoSteve JangoSteve committed Feb 19, 2013
Showing with 18 additions and 3 deletions.
  1. +1 −3 src/rails.js
  2. +17 −0 test/public/test/data-disable.js
View
@@ -276,9 +276,7 @@
enableElement: function(element) {
if (element.data('ujs:enable-with') !== undefined) {
element.html(element.data('ujs:enable-with')); // set to old enabled state
- // this should be element.removeData('ujs:enable-with')
- // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
- element.data('ujs:enable-with', false); // clean up cache
+ element.removeData('ujs:enable-with'); // clean up cache
}
element.unbind('click.railsDisable'); // enable element
}
@@ -207,6 +207,23 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e
}, 30);
});
+asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', 6, function() {
+ var link = $('a[data-disable-with]').attr('data-remote', true).attr('href', '/error');
+
+ checkEnabledState(link, 'Click me');
+
+ link
+ .bind('ajax:beforeSend', function() {
+ checkDisabledState(link, 'clicking...');
+ })
+ .trigger('click');
+
+ setTimeout(function() {
+ checkEnabledState(link, 'Click me');
+ start();
+ }, 30);
+});
+
asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not disable when `ajax:beforeSend` event is cancelled', 8, function() {
var form = $('form[data-remote]'),
input = form.find('input:text'),

0 comments on commit 610dfb8

Please sign in to comment.