Fundementally, Vaidation works
like this:
- A form is constructed
in HTML with no special validation code
- After the form is complete,
construct and configure the form validator for 'theForm'.
- The FormValidator
constructor, which takes up to three arguments:
- formName: the name of
the form
- onLoadUser: Optional: the name
of a function to invoke when the form is loaded
- onSubmitUser: Optional: the name
of a function to invoke when the form is submited
- The set method takes n
pair of name/values, and passes these values to each field validator upon construction.
- The attach method takes
up to four args:
- fldName: the name of
the field as referenced in the form
- type: Optional: the
type of validator. The default is 'Simple'
- prompt: Optional: the
name of the field as it will be shown to the user. The default is a
transformation of the fldName
- description: Optional:
additional description
- The attach method returns a Validator of
the type requested. All Validators should either inherit the
SimpleValidator, or just look like one.
- The set method, just
like for forms, takes n pairs of name/values
- The setDescription
method, used to set the description
- The setPrompt method,
used to set the prompt and
description
- The SimpleValidator, or
Simple supports the following types of validation for
strings:
- required -- true/false
- minLen -- set to the minimum
length
- maxLen -- set to the maximum
length
- The
Date validator: for dates with optional min/max date
validation
- The Email validator for
email
- The Integer validator for
integers with optional min/max validation
- The
Float Validator for floats with optional min/max
& precision validation and formating
- Just like forms, field validators support
some pseudo events:
- onLoadUser: invoked when
the form is loaded
- onSubmitUser: invoked
when the form is submited. Good for final formatting prior to being sent to
the server
- onChangeUser: invoked
when the value changes, on a key-by-key basis
- onClickUser: invoked
when the onClick event is received
- onBlurUser: invoked when
the onBlur event is received
- onFocusUser: invoked
when the onFocus event is received
- onKeyUpUser: invoked
when the onKeyUp event is received