| 1 |
This is a prototype/scriptaculous based validator. |
| 2 |
This validator is small, and highly configurable. You dont need a detailed |
| 3 |
knowledge of javascript to start using it. |
| 4 |
|
| 5 |
Your first point of call is tests/index.html. To start using validator |
| 6 |
* Make sure your form and form elements all have id |
| 7 |
* Make sure your form has an action |
| 8 |
* Make sure you have a submit button |
| 9 |
|
| 10 |
* You can specify a function as your form action, see the second form |
| 11 |
in tests/index.html |
| 12 |
|
| 13 |
* All the fields you want to validate will have a title attribute. This |
| 14 |
attribute will specify what kind of validation you want. You can also |
| 15 |
have a list of space, separated titles if you want more than one type |
| 16 |
of validation to be carried out. tests/index.html contain these scenarios. |
| 17 |
|
| 18 |
|
| 19 |
The file you will need to look at next is validator_rules.js. This is required |
| 20 |
only if you need to tweak validator in any way. If you are confortable with |
| 21 |
regular expressions, you can loook at var regex. |
| 22 |
|
| 23 |
All changes you might ever want to make, should be done to this file. |
| 24 |
|
| 25 |
The keen eyed will see that some messages dont have the corresponding |
| 26 |
regex definition. These ones will have their regex generated at run time. |
| 27 |
|
| 28 |
If you also wish to generate some regex and/or messages at run time, use the |
| 29 |
function hooks(). An example is provided for you. Note that hooks should |
| 30 |
always return a true only when a hook is defined, that is the reson for the |
| 31 |
regular expression test as the first line of the function, else just return false. |
| 32 |
The variable v is the value of the element's title(if you provide multiple |
| 33 |
titles, hooks will be called on that element for each title) and e is the |
| 34 |
element being called. An example is provided in validator.js. |
| 35 |
|
| 36 |
Please do not redefine the regex already defined without deleting them. |
| 37 |
This might cause undesirable effects. |
| 38 |
|
| 39 |
Please do not name another method as validator_hooks or name a method starting |
| 40 |
with validator_, this might conflict with some methods in the plugin. |
| 41 |
|
| 42 |
If you have a runtime determined regex, eg length{x} and a standard predefined regex, |
| 43 |
e.g required, the standard predefined should come first in the title, this is just |
| 44 |
a good practice, any arrangement will also work as well. eg |
| 45 |
<input type="text" name="fred" id="fred" title="required email length{6}" /> |
| 46 |
|
| 47 |
|
| 48 |
NOTE |
| 49 |
For equals#id, {n} will be replaced by document.getElementById(id).name |
| 50 |
|
| 51 |
BUGS |
| 52 |
Making the id of a form field id i.e <input id="id" /> will break down validator completely |