X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Fforms.js;fp=public%2Fjs%2Fforms.js;h=738b056f67c6840d8dd9ec8df9c97f1baea0ccf9;hb=4360d632b91c3e17a776bc9308eba3a3915f7005;hp=9c84d5b0581e0a3097ee9ef48cc69068ef058c40;hpb=9efd079d59d269811abc4c551b2f39ab2e6a05fb;p=syj.git diff --git a/public/js/forms.js b/public/js/forms.js index 9c84d5b..738b056 100644 --- a/public/js/forms.js +++ b/public/js/forms.js @@ -1,5 +1,17 @@ /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier, and is published under the AGPL license. */ +Element.addMethods(['input', 'textarea'], { + check: function(control, callback, errorMessage) { + if (callback.call(control)) { + return true; + } + control.insert({ + after: new Element("div", {className: 'error'}).update(errorMessage) + }); + return false; + } +}); + Element.addMethods('form', { focus: function(form) { var tofocus, error; @@ -12,23 +24,28 @@ Element.addMethods('form', { tofocus = form.down('input:not([readonly],[disabled]),textarea:not([readonly][disabled])'); } if (tofocus) { - if (error && (typeof tofocus.highlight == "function")) { + if (error && (typeof tofocus.highlight === "function")) { tofocus.highlight('#F08080'); } tofocus.focus(); tofocus.select(); } - } -}); + }, -Element.addMethods(['input', 'textarea'], { - check: function(control, callback, errorMessage) { - if (callback.call(control)) { - return true; - } - control.insert({ - after: new Element("div", {className: 'error'}).update(errorMessage) + checkEmptyElements: function(form, errorMessage) { + var results = []; + form.select('.required').each(function(elt) { + var id = elt.getAttribute('for'), control = $(id); + if (!control) { + return; + } + if (!control.check(function() { + return !this.value.strip().empty(); + }, errorMessage)) { + results.push(control); + } }); - return false; + return results; } + });