]> dev.renevier.net Git - syj.git/blob - public/js/forms.js
highlight for input on errors
[syj.git] / public / js / forms.js
1 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2     and is published under the AGPL license. */
3 Element.addMethods('form', {
4     focus: function(form) {
5         var tofocus, error;
6
7         tofocus = null;
8         error = form.down('.error');
9         if (error) {
10             tofocus = error.previous('input,textarea');
11         } else {
12             tofocus = form.down('input:not([readonly],[disabled]),textarea:not([readonly][disabled])');
13         }
14         if (tofocus) {
15             if (error && (typeof tofocus.highlight == "function")) {
16                 tofocus.highlight('#F08080');
17             }
18             tofocus.focus();
19             tofocus.select();
20         }
21     }
22 });
23
24 Element.addMethods(['input', 'textarea'], {
25     check: function(control, callback, errorMessage) {
26         if (callback.call(control)) {
27             return true;
28         }
29         control.insert({
30             after: new Element("div", {className: 'error'}).update(errorMessage)
31         });
32         return false;
33     }
34 });