Version 1.2 glow.forms.Form
API Quick Reference
JavaScript is required to use the quick reference
Create an object to add tests to.
Further Info & Examples
Constructor
new glow.forms.Form(formNode, opts)Parameters
- formNode
- Type
- glow.dom.NodeList | Selector
- opts
- Type
- Object
- Optional
- Yes
- onValidate
Handles the 'validate' event when all tests are complete.
- Type
- Function
- Optional
- Yes
Examples
myForm = new glow.forms.Form( glow.dom.get("#htmlFormId"), { onValidate: function(results) { // ... } } );
Properties
- formNode
- opts
- Type
- Object
Methods
- addTests
Add one or more tests to a field.
Synopsis
myForm.addTests(fieldName, spec);Parameters
- fieldName
- Type
- String
The name of the field to add tests to.
- spec
- Type
- Array
- Optional
- Yes
Test specifications identify the type of test to be run on a field to determine whether it contains desired data. See docs on the types of tests.
Example
//pattern for a test specification [ "testName", //name of the test to run { arg : 5, //an argument for the test, not all tests need this on : "submit change", //when should this test be run? message : "Incorrect value" //a custom error message to display } ]//setting a form up for validation var myForm = new glow.forms.Form(glow.dom.get("#myFormId")) .addTests( "username", ["required"], ["maxLen", {arg: 12, message: "Name must be les than 12 characters long."}] ) .addTests( "email", ["isEmail"] );- validate
Run validation tests.