X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=public%2Fjs%2Futils.js;h=1651b618241ad1ad3e531c5a2a063d7c9c78b279;hp=b16a9c2ec4206c1ec83bba7ca38e20f425585a60;hb=c1aeb7538786d8c9f3b3337c0b71e21ef89d9c77;hpb=69cbaf628f5576754d4553c021315188e22d24af diff --git a/public/js/utils.js b/public/js/utils.js index b16a9c2..1651b61 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -212,7 +212,8 @@ Ajax.Responders.register({ // wrapper around Form.request that sets up the submit listener, stops the // submit event, calls presubmit function, calls Form.request and calls a -// postsubmit function +// postsubmit function. If form has some visible and activated file inputs, +// execute presubmit, but do not send the file with ajax. Element.addMethods('form', { ajaxize : function(form, options) { var reqoptions; @@ -220,7 +221,6 @@ Element.addMethods('form', { options = Object.clone(options || {}); $(form).observe('submit', function(evt) { - evt.stop(); // cancel form submission reqoptions = Object.clone(options); delete(reqoptions.presubmit); @@ -229,10 +229,30 @@ Element.addMethods('form', { if (Object.isFunction(options.presubmit)) { if (options.presubmit(this) === false) { + evt.stop(); // cancel form submission return; } } + // get list of input file not disabled, and not hidden + if (this.getInputs('file').find(function(elt) { + if (elt.disabled) { + return false; + } + while (elt && $(elt).identify() !== this.identify()) { + if (!elt.visible()) { + return false; + } + elt = elt.parentNode; + } + return true; + }.bind(this))) { + // form has some file inputs. Do not manage on our own. + return; + } + + evt.stop(); // cancel form submission + var params = reqoptions.parameters, action = this.readAttribute('action') || ''; if (action.blank()) {