From: arno Date: Fri, 20 Aug 2010 09:30:25 +0000 (+0200) Subject: disable form during request in Ajaxize X-Git-Tag: v0.2~30 X-Git-Url: https://dev.renevier.net/?p=syj.git;a=commitdiff_plain;h=c7c35fba8c1ded1e4d6e04a3c9e2082ad9ace60d disable form during request in Ajaxize --- diff --git a/public/js/utils.js b/public/js/utils.js index f437d15..85fe57a 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -212,11 +212,37 @@ Element.addMethods('form', { reqoptions.method = this.method; } + if (reqoptions.onFailure) { + reqoptions.onFailure = reqoptions.onFailure.wrap(function(proceed, transport, json) { + form.enable(); + proceed(transport, json); + }); + } else { + reqoptions.onFailure = function() { + form.enable(); + }; + } + + if (reqoptions.onSuccess) { + reqoptions.onSuccess = reqoptions.onSuccess.wrap(function(proceed, transport, json) { + form.enable(); + proceed(transport, json); + }); + } else { + reqoptions.onSuccess = function() { + form.enable(); + }; + } + new Ajax.TimedRequest(action, options.delay || 20, reqoptions); if (Object.isFunction(options.postsubmit)) { options.postsubmit(this); } + Form.getElements(form).each(function(elt) { + elt.blur(); + elt.disable(); + }); }); },