Skip to content
Browse files

data-disable-with should work for non remote forms too

  • Loading branch information...
1 parent bcaad37 commit abe2f8c2f4fa53391ed954c38a596c2754a78509 @lucasuyezu lucasuyezu committed with josevalim
Showing with 28 additions and 1 deletion.
  1. +1 −1 src/rails.js
  2. +27 −0 test/public/test/data-disable.js
View
2 src/rails.js
@@ -119,7 +119,7 @@ jQuery(function ($) {
};
$(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
- $(disable_with_form_not_remote_selector).live('click', disable_with_input_function);
+ $(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
$(disable_with_form_remote_selector).live('ajax:complete', function () {
$(this).find(disable_with_input_selector).each(function () {
View
27 test/public/test/data-disable.js
@@ -18,6 +18,19 @@ module('data-disable', {
'value': 'john'
}));
+ $('#fixtures').append($('<form />', {
+ action: App.url('update'),
+ method: 'post'
+ }));
+
+ $('form:not([data-remote])').append($('<input />', {
+ id: 'submit',
+ 'data-disable-with': 'submitting ...',
+ type: 'submit',
+ name: 'submit',
+ value: 'Submit'
+ }));
+
}
});
@@ -39,3 +52,17 @@ test('triggering ajax callbacks on a form with data-disable attribute', function
});
+test('clicking on non-ajax Submit input tag with data-disable-with attribute', function(){
+ expect(4);
+
+ equals($('input:disabled').size(), 0, 'input field should not be disabled');
+ equals($('input[type=submit]').val(), 'Submit', 'input field should have value given to it');
+
+ $('form:not([data-disable-with])').live('submit', function (e) {
+ e.preventDefault();
+ }).trigger('click');
+
+ equals($('input:disabled').size(), 1, 'input field should be disabled');
+ equals($('input:disabled').val(), 'submitting ...', 'input field should have disabled value given to it');
+
+});

0 comments on commit abe2f8c

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