Skip to content
Browse files

Added test case for form input disabling when ajax:beforeSend canceled

  • Loading branch information...
1 parent b07d212 commit 82292010fb1743f038ab72b1f1e994e91be3eda3 @JangoSteve JangoSteve committed Nov 25, 2011
Showing with 26 additions and 3 deletions.
  1. +4 −3 src/rails.js
  2. +22 −0 test/public/test/data-disable.js
View
7 src/rails.js
@@ -301,10 +301,10 @@
if (link.data('remote') !== undefined) {
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
- if(rails.handleRemote(link) === false) {
- rails.enableElement($(this));
- }
+
+ if (rails.handleRemote(link) === false) { rails.enableElement(link); }
return false;
+
} else if (link.data('method')) {
rails.handleMethod(link);
return false;
@@ -343,6 +343,7 @@
rails.handleRemote(form);
return false;
+
} else {
// slight timeout so that the submit button gets properly serialized
setTimeout(function(){ rails.disableFormElements(form); }, 13);
View
22 test/public/test/data-disable.js
@@ -200,3 +200,25 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e
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'),
+ button = $('<button data-disable-with="submitting ..." name="submit2">Submit</button>').appendTo(form),
+ textarea = $('<textarea data-disable-with="processing ..." name="user_bio">born, lived, died.</textarea>').appendTo(form),
+ submit = $('<input type="submit" data-disable-with="submitting ..." name="submit2" value="Submit" />').appendTo(form);
+
+ form
+ .bind('ajax:beforeSend', function() {
+ return false;
+ })
+ .trigger('submit');
+
+ checkEnabledState(input, 'john');
+ checkEnabledState(button, 'Submit');
+ checkEnabledState(textarea, 'born, lived, died.');
+ checkEnabledState(submit, 'Submit');
+
+ start();
+
+});

0 comments on commit 8229201

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