Skip to content
Browse files

Cancelling a remote link in the ajax:beforeSend event now re-enables …

…the link
  • Loading branch information...
1 parent b4731f9 commit 7e0ea5c946aaa97376afcae8ce826c0e1029b0ad @sskirby sskirby committed Oct 24, 2011
Showing with 27 additions and 1 deletion.
  1. +1 −1 src/rails.js
  2. +26 −0 test/public/test/data-disable.js
View
2 src/rails.js
@@ -150,7 +150,7 @@
// Only pass url to `ajax` options if not blank
if (url) { options.url = url; }
- rails.ajax(options);
+ return rails.ajax(options);
} else {
return false;
}
View
26 test/public/test/data-disable.js
@@ -206,3 +206,29 @@ asyncTest('remote link with "data-disable-with" attribute disables and re-enable
start();
}, 30);
});
+
+asyncTest('remote link with "data-disable-with" attribute disables and re-enables when ajax:beforeSend event is cancelled', 6, function() {
+ var link = $('a[data-disable-with]').attr('data-remote', true);
+
+ function checkEnabledLink() {
+ ok(!link.data('ujs:enable-with'), 'link should not be disabled');
+ equal(link.html(), 'Click me', 'link should have value given to it');
+ }
+ checkEnabledLink();
+
+ function checkDisabledLink() {
+ ok(link.data('ujs:enable-with'), 'link should be disabled');
+ equal(link.html(), 'clicking...');
+ }
+
+ link
+ .bind('ajax:beforeSend', function() {
+ checkDisabledLink();
+ return false;
+ })
+ .trigger('click');
+ setTimeout(function() {
+ checkEnabledLink();
+ start();
+ }, 30);
+});

0 comments on commit 7e0ea5c

Please sign in to comment.
Something went wrong with that request. Please try again.