Validatious 2.0

Easy form validation with unobtrusive JavaScript

Configuring reporting

The error reporting extension is implemented as a mixin module that is used to augment the prototype objects of v2.Field and v2.Form. For this reason, the same properties can be edited on both v2.Field.prototype and v2.Fieldset.prototype. When you see something like "... can be configured through messagesClass" it means you can specify the messagesClass property on either one of:

  1. Through individual objects
  2. Through v2.Field.prototype
  3. Through v2.Fieldset.prototype

...depending on the desired effect.

Individual objects

When you alter a property on a single field or fieldset object, then the effect will only affect that single field/fieldset:

var field = new v2.Field('name');
field.successClass = 'yuppi';

This will cause the class name yuppi to be added to the container of the name input when validation passes on this field.

Through v2.Field.prototype

Changing the setting on the field prototype object will affect every field object, including objects created before this setting is applied*.

// Make the fail class "warning" for all fields
v2.Field.prototype.failureClass = 'warning';

* There's one exception here that may bite you. Objects instantiated before the setting is changed will also have the same setting changed unless they already had their value changed directly on the object.

The reason for this is how JavaScript prototypes work: As long as an object has not made any changes to a property on its prototype, it will refer to the prototype. As soon as the property is changed on the object, the value is copied down to the object and the link to the prototype property is no longer there. This is best shown through an example:

var name = new v2.Field('name');
var email = new v2.Field('email');
email.failureClass = 'wrong';

name.failureClass;  // 'error', default value
email.failureClass; // 'wrong', edited directly on object

v2.Field.prototype.failureClass = 'warning';
var phone = new v2.Field('phone');

name.failureClass;  // 'warning', updated prototype value
email.failureClass; // 'wrong', edited directly on object, unchanged
phone.failureClass; // 'warning', prototype value

Next: Class names | Back to Reporting extension features index

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