diff --git a/src/rails.js b/src/rails.js index cbb348b1..4dcb3779 100644 --- a/src/rails.js +++ b/src/rails.js @@ -119,8 +119,8 @@ var form = $(this), remote = form.attr('data-remote') != undefined; if (!allowAction(form)) return false; - // skip other logic when required values are missing, but don't cancel the event - if (requiredValuesMissing(form)) return; + // skip other logic when required values are missing + if (requiredValuesMissing(form)) return !remote; if (remote) { handleRemote(form); diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index 69870867..f0c00117 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -46,6 +46,9 @@ asyncTest('blank required form input field should abort request', 1, function() .bind('ajax:beforeSend', function() { ok(false, 'ajax:beforeSend should not run'); }) + .bind('iframe:loading', function() { + ok(false, 'form should not get submitted'); + }) .trigger('submit'); setTimeout(function() { diff --git a/test/public/test/settings.js b/test/public/test/settings.js index b1126cab..616ebc68 100644 --- a/test/public/test/settings.js +++ b/test/public/test/settings.js @@ -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'); }; +// hijacks normal form submit; lets it submit to an iframe to prevent +// navigating away from the test suite $(document).bind('submit', function(e) { if (!e.isDefaultPrevented()) { var form = $(e.target), action = form.attr('action'), @@ -36,5 +38,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 }); } -}) +});