Skip to content

Commit

Permalink
non-remote forms with "data-disable-with" perform disabling asynchron…
Browse files Browse the repository at this point in the history
…ously

This gives form fields a chance to get serialized
  • Loading branch information
mislav committed Feb 10, 2011
1 parent 2ce5740 commit 900d714
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/rails.js
Expand Up @@ -146,7 +146,8 @@
handleRemote(form);
return false;
} else {
disableFormElements(form);
// slight timeout so that the submit button gets properly serialized
setTimeout(function(){ disableFormElements(form) }, 13);
}
});

Expand Down
14 changes: 9 additions & 5 deletions test/public/test/data-disable.js
Expand Up @@ -40,7 +40,7 @@ asyncTest('form input field with "data-disable-with" attribute', 7, function() {
equal(input.val(), 'processing ...', 'input field should have disabled value given to it');
});

asyncTest('form submit button with "data-disable-with" attribute', 7, function(){
asyncTest('form submit button with "data-disable-with" attribute', 6, function(){
var form = $('form:not([data-remote])'), input = form.find('input[type=submit]');

ok(!input.is(':disabled'), 'input field should not be disabled');
Expand All @@ -51,11 +51,15 @@ asyncTest('form submit button with "data-disable-with" attribute', 7, function()
equal(input.val(), 'submitting ...');
}

// WEEIRDD: attaching this handler makes the test work in IE7
form.bind('iframe:loading', function(e, form) {});

form.bind('iframe:loaded', function(e, data) {
checkDisabledState();
strictEqual(data.params.submit2, undefined);
start();
setTimeout(function() {
checkDisabledState();
start();
}, 30);
}).trigger('submit');

checkDisabledState();
setTimeout(checkDisabledState, 30);
});
2 changes: 1 addition & 1 deletion test/public/test/settings.js
Expand Up @@ -31,6 +31,6 @@ $(document).bind('submit', function(e) {
if (action.indexOf('iframe') < 0) form.attr('action', action + '?iframe=true')
form.attr('target', name);
$('#qunit-fixture').append(iframe);
$.event.trigger('iframe:loading', { form: form });
$.event.trigger('iframe:loading', form);
}
});

0 comments on commit 900d714

Please sign in to comment.