1 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2 and is published under the AGPL license. */
3 Element.addMethods(['input', 'textarea'], {
4 check: function(control, callback, errorMessage) {
5 if (callback.call(control)) {
9 after: new Element("div", {className: 'error'}).update(errorMessage)
15 Element.addMethods('form', {
16 focus: function(form) {
20 error = form.down('.error');
22 tofocus = error.previous('input,textarea');
24 tofocus = form.down('input:not([readonly],[disabled]),textarea:not([readonly][disabled])');
27 if (error && (typeof tofocus.highlight === "function")) {
28 tofocus.highlight('#F08080');
35 checkEmptyElements: function(form, errorMessage) {
37 form.select('.required').each(function(elt) {
38 var id = elt.getAttribute('for'), control = $(id);
42 if (!control.check(function() {
43 return !this.value.strip().empty();
45 results.push(control);