]> dev.renevier.net Git - syj.git/blob - public/js/forms.js
version 0.1
[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             tofocus.focus();
16             tofocus.select();
17         }
18     }
19 });
20
21 Element.addMethods(['input', 'textarea'], {
22     check: function(control, callback, errorMessage) {
23         if (callback.call(control)) {
24             return true;
25         }
26         control.focus();
27         control.select();
28         control.insert({
29             after: new Element("div", {className: 'error'}).update(errorMessage)
30         });
31         return false;
32     }
33 });