From 4c499b39885d07d54efbcdd1bf4c090f59d68a77 Mon Sep 17 00:00:00 2001 From: Johan Buts Date: Wed, 2 Feb 2011 15:16:45 +0100 Subject: [PATCH 1/3] Do not use attribute disabled when you are using data-disabled-with because it will not submit your forms in ie7. --- src/rails.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index 4dcb3779..73fdb9ce 100644 --- a/src/rails.js +++ b/src/rails.js @@ -77,15 +77,14 @@ form.find('input[data-disable-with]').each(function() { var input = $(this); input.data('ujs:enable-with', input.val()) - .val(input.attr('data-disable-with')) - .attr('disabled', 'disabled'); + .val(input.attr('data-disable-with')); }); } function enableFormElements(form) { form.find('input[data-disable-with]').each(function() { var input = $(this); - input.val(input.data('ujs:enable-with')).removeAttr('disabled'); + input.val(input.data('ujs:enable-with')); }); } @@ -117,6 +116,11 @@ $('form').live('submit.rails', function(e) { var form = $(this), remote = form.attr('data-remote') != undefined; + if (form.data('submitted')) { + return false; + } else { + form.data('submitted', true); + } if (!allowAction(form)) return false; // skip other logic when required values are missing From 469190763f80b21ee220b66ba813989bab97491b Mon Sep 17 00:00:00 2001 From: Johan Buts Date: Wed, 2 Feb 2011 15:18:37 +0100 Subject: [PATCH 2/3] Only check for required fields if you really want to have that functionality --- src/rails.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 73fdb9ce..40abb85a 100644 --- a/src/rails.js +++ b/src/rails.js @@ -124,7 +124,9 @@ if (!allowAction(form)) return false; // skip other logic when required values are missing - if (requiredValuesMissing(form)) return !remote; + if (form.attr('data-validate') != undefined) { + if (requiredValuesMissing(form)) return !remote; + } if (remote) { handleRemote(form); From ca19a5ee7a9bfec7f166c3b9df5f5953124471a9 Mon Sep 17 00:00:00 2001 From: Johan Buts Date: Thu, 3 Feb 2011 13:31:16 +0100 Subject: [PATCH 3/3] Fixing issue in ie where the form won't submit if you press enter instead of clicking the button --- src/rails.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 40abb85a..68b5cd52 100644 --- a/src/rails.js +++ b/src/rails.js @@ -136,6 +136,16 @@ } }); + // Implement this for ie, because if you press enter on a submit it has a weird execution order + if ($.browser.msie) { + $('input').live('keydown', function(e){ + if (e.keyCode == 13) { + $(this).parents('form').submit(); + return false; + } + }); + } + $('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() { var button = $(this); if (!allowAction(button)) return false; @@ -143,7 +153,7 @@ var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null; button.closest('form').data('ujs:submit-button', data); }); - + $('form').live('ajax:beforeSend.rails', function(event) { if (this == event.target) disableFormElements($(this)); });