Class RapidContext.Widget.FormValidator

Extends: RapidContext.Widget

The form validator widget class. Provides visual feedback on form validation failures, using a <span> HTML element. It is normally hidden by default and may be configured to only modify its related form field.

Source code: RapidContext_Widget_FormValidator.js

Class Summary
 
Creates a new form validator widget.
Field Summary
 
The default validation message.
 
The form field name to validate.
 
The validator function in use.
Method Summary
 
addError(field, message)
Adds a validation error message for the specified field.
 
Resets this form validator.
 
setAttrs(attrs)
Updates the widget or HTML DOM node attributes.
 
verify(field, value)
Verifies a form field with this validator.
Methods borrowed from class RapidContext.Widget:
addAll, addChildNode, addClass, animate, blurAll, destroy, disable, enable, getChildNodes, hasClass, hide, isDisabled, isHidden, removeAll, removeChildNode, removeClass, setStyle, show, toggleClass, uid
Class Detail
RapidContext.Widget.FormValidator(attrs)
Creates a new form validator widget.
JavaScript:
var field = RapidContext.Widget.TextField({ name: "name", helpText: "Your Name Here" });
var attrs = { name: "name", message: "Please enter your name to proceed." };
var valid = RapidContext.Widget.FormValidator(attrs);
var exampleForm = RapidContext.Widget.Form({}, field, valid);
User Interface XML:
<Form id="exampleForm">
  <TextField name="name" helpText="Your Name Here" />
  <FormValidator name="name" message="Please enter your name to proceed." />
</Form>
Parameters:
{Object} attrs
the widget and node attributes
{String} attrs.name
the form field name to validate
{Boolean} attrs.mandatory Optional
the mandatory field flag, defaults to true
{String/RegExp} attrs.regex Optional
the regular expression to match the field value against, defaults to null
{String} attrs.display Optional
the validator display setting (either none, icon, text or both), defaults to both
{String} attrs.message Optional
the message to display, defaults to the validator function error message
{Function} attrs.validator Optional
the validator function
{Boolean} attrs.hidden Optional
the hidden widget flag, defaults to false
Returns:
{Widget} the widget DOM node
Field Detail
{String} name
The form field name to validate.

{String} message
The default validation message.

{Function} validator
The validator function in use.
Method Detail
setAttrs(attrs)
Updates the widget or HTML DOM node attributes.
Parameters:
{Object} attrs
the widget and node attributes to set
{String} attrs.name Optional
the form field name to validate
{Boolean} attrs.mandatory Optional
the mandatory field flag
{String/RegExp} attrs.regex Optional
the regular expression to match the field value against
{String} attrs.display Optional
the validator display setting (either none, icon, text or both)
{String} attrs.message Optional
the message to display
{Function} attrs.validator Optional
the validator function
{Boolean} attrs.hidden Optional
the hidden widget flag

reset()
Resets this form validator. This will hide any error messages and mark all invalidated fields as valid.

Note that this method is normally not called directly, instead the validation is reset by the RapidContext.Widget.Form widget.

{Boolean/MochiKit.Async.Deferred} verify(field, value)
Verifies a form field with this validator. If the form field value doesn't match this validator, the field will be invalidated until this validator is reset.

Note that this method is normally not called directly, instead the validation is performed by the RapidContext.Widget.Form widget.
Parameters:
{Widget/Node} field
the form field DOM node
{String} value Optional
the form field value to check
Returns:
{Boolean/MochiKit.Async.Deferred} true if the form validated successfully, false if the validation failed, or a MochiKit.Async.Deferred instance if the validation was deferred

addError(field, message)
Adds a validation error message for the specified field. If the field is already invalid, this method will not do anything.

Note that this method is normally not called directly, instead the validation is performed by the RapidContext.Widget.Form widget.
Parameters:
{Widget/Node} field
the field DOM node
{String} message
the validation error message