Class MochiKit.Widget.FormValidator
Extends
MochiKit.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.
Defined in: Widget.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Creates a new form validator widget.
|
Field Attributes | Field Name and Description |
---|---|
The default validation message.
|
|
The form field name to validate.
|
|
The validator function in use.
|
- Fields borrowed from class MochiKit.Widget:
- _id, Classes
Method Attributes | Method Name and Description |
---|---|
addError(field, message)
Adds a validation error message for the specified field.
|
|
reset()
Resets this form validator.
|
|
setAttrs(attrs)
Updates the widget or HTML DOM node attributes.
|
|
verify(field)
Verifies a form field with this validator.
|
- Methods borrowed from class MochiKit.Widget:
- _animQueueId, _createWidgetTreeElem, _eventHandler, _widgetMixin, addAll, addChildNode, addClass, animate, blurAll, createWidget, createWidgetTree, destroy, destroyWidget, emitSignal, getChildNodes, hasClass, hide, isFormField, isHidden, isWidget, removeAll, removeChildNode, removeClass, setStyle, show, toggleClass
Class Detail
MochiKit.Widget.FormValidator(attrs)
Creates a new form validator widget.
- 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" or "error"), defaults to "error"
- {String} attrs.message Optional
- the message to display, defaults to the validator function error message
- {Function} attrs.validator Optional
- the validator function
- Returns:
- {Widget} the widget DOM node
Field Detail
{String}
message
The default validation message.
{String}
name
The form field name to validate.
{Function}
validator
The validator function in use.
Method Detail
addError(field, message)
Adds a validation error message for the specified field. If the
field is already invalid, this method will not do anything.
- Parameters:
- {Widget/Node} field
- the field DOM node
- {String} message
- the validation error message
reset()
Resets this form validator. This will hide any error messages and
mark all invalidated fields as valid.
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" or "error")
- {String} attrs.message Optional
- the message to display
- {Function} attrs.validator Optional
- the validator function
{Boolean/MochiKit.Async.Deferred}
verify(field)
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.
- Parameters:
- {Widget/Node} field
- the form field DOM node
- 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