Validatious 2.0

Easy form validation with unobtrusive JavaScript

Specify field names for error messages

Validatious aims to generate reasonable error messages by resolving field names. There's three ways Validatious can find the name of a field:

  1. The default is to find the label associated with the field through the input/select/textarea id attribute and the label for attribute. The innerHTML of the label will be used as the field name.
  2. If the label element has a non-empty title attribute, this will be used instead of the innerHTML.
  3. If no label can be found, the id attribute of the field element will be used. If no id is found either, the name attribute is used.

In addition to these, you may also set the name of a field programmatically through v2.$f(id).setName(newName). Doing this will override the search described above. From v2.Field objects, you can set the name through field.element.setName(name);.

Examples

The following example shows the default behaviour with a label without the title attribute. If you post the form with an empty name or only a single character you'll see how "Your name" is used in both the (default) error messages.

The following example shows how setting the title attribute on the label allows you to use a different field name in the error messages than what is displayed in the label.

The last example shows how Validatious will use the id of the field when no label can be found. Notice that the label is there, but the for/id connection is wrong.

Next: Multilingual messages | Back to Core API features index

© 2008 Christian Johansen. Validatious is licensed with a BSD License, documentation and site content with CC Attribution-Share Alike. About.