Browse files

fix remote form not submitting when required values missing

  • Loading branch information...
1 parent a16fc2c commit 6c996cba7ce0b1834eee35564a3af7c7523179a7 @mislav mislav committed Feb 2, 2011
Showing with 9 additions and 3 deletions.
  1. +2 −2 src/rails.js
  2. +3 −0 test/public/test/call-remote-callbacks.js
  3. +4 −1 test/public/test/settings.js
View
4 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);
View
3 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() {
View
5 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 });
}
-})
+});

0 comments on commit 6c996cb

Please sign in to comment.