Skip to content

Commit

Permalink
fix remote form not submitting when required values missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Feb 2, 2011
1 parent a16fc2c commit 6c996cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rails.js
Expand Up @@ -119,8 +119,8 @@
var form = $(this), remote = form.attr('data-remote') != undefined; var form = $(this), remote = form.attr('data-remote') != undefined;
if (!allowAction(form)) return false; if (!allowAction(form)) return false;


// skip other logic when required values are missing, but don't cancel the event // skip other logic when required values are missing
if (requiredValuesMissing(form)) return; if (requiredValuesMissing(form)) return !remote;


if (remote) { if (remote) {
handleRemote(form); handleRemote(form);
Expand Down
3 changes: 3 additions & 0 deletions test/public/test/call-remote-callbacks.js
Expand Up @@ -46,6 +46,9 @@ asyncTest('blank required form input field should abort request', 1, function()
.bind('ajax:beforeSend', function() { .bind('ajax:beforeSend', function() {
ok(false, 'ajax:beforeSend should not run'); ok(false, 'ajax:beforeSend should not run');
}) })
.bind('iframe:loading', function() {
ok(false, 'form should not get submitted');
})
.trigger('submit'); .trigger('submit');


setTimeout(function() { setTimeout(function() {
Expand Down
5 changes: 4 additions & 1 deletion test/public/test/settings.js
Expand Up @@ -27,6 +27,8 @@ App.assert_request_path = function(request_env, path) {
equal(request_env['PATH_INFO'], path, 'request should be sent to right url'); equal(request_env['PATH_INFO'], path, 'request should be sent to right url');
}; };


// hijacks normal form submit; lets it submit to an iframe to prevent
// navigating away from the test suite
$(document).bind('submit', function(e) { $(document).bind('submit', function(e) {
if (!e.isDefaultPrevented()) { if (!e.isDefaultPrevented()) {
var form = $(e.target), action = form.attr('action'), var form = $(e.target), action = form.attr('action'),
Expand All @@ -36,5 +38,6 @@ $(document).bind('submit', function(e) {
if (action.indexOf('iframe') < 0) form.attr('action', action + '?iframe=true') if (action.indexOf('iframe') < 0) form.attr('action', action + '?iframe=true')
form.attr('target', name); form.attr('target', name);
$('#qunit-fixture').append(iframe); $('#qunit-fixture').append(iframe);
$.event.trigger('iframe:loading', { form: form });
} }
}) });

0 comments on commit 6c996cb

Please sign in to comment.