Please turn on JavaScript. To find out how to do this visit the WebWise JavaScript guide.

Create an object to add tests to.

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. Default is glow.forms.feedback.defaultFeedback.

Type
Function
Optional
Yes

Examples

myForm = new glow.forms.Form("#htmlFormId" ,{
  onValidate: function(results) {
    // ...
  }
});

Properties

formNode

NodeList containing the form element

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.

Synopsis

myForm.validate(eventName, fieldName);

Parameters

eventName
Type
String
Default
'submit'
Optional
Yes

Run only tests tied to this eventname.

fieldName
Type
String
Optional
Yes

Run only tests attached to the form element with this name.

Description

This is called automatically depending on the tests added to the form. However, you can trigger validation manually

Events

validate

Fired whenever the glow tries to validate a form.

Synopsis

glow.events.addListener(myForm, "validate", function(event) {
    // ...
});

Arguments

event
Type
glow.forms.ValidateResult

A specialised Event object.

Description

If you prefer you can set a handler for this event via the onValidate option of the glow.forms.Form constructor.

Example

glow.events.addListener(myForm, "validate", function(e) {
  if (e.eventName == 'submit') {
    if (e.errorCount == 0) { alert("Well done!"); }
    else { e.preventDefault(); } // stop the submit from happening
  }
});
Documentation generated by JsDoc Toolkit 2.1.0 on Thu Jul 07 2011 12:47:29 GMT+0100 (BST)

BBC © 2014 The BBC is not responsible for the content of external sites. Read more.

This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.