Form validation examples using Zebda

1. Inline validation + conditional rules

Type

Conditional rules are defined in beforeValidate:

	if ($F('chk1')){	//Checkbox is checked?
		txt = $('txt2');  //Text element
		cond = Rule.Conditions.required;
		condOptions = {};
		r = new Rule(txt, cond, condOptions, 'Conditional text is required');
		FormValidator.Element.addRule(txt,r);
	}

The condition cond could be any function that takes one argument (the field value) and returns true when the condition is satisfied.

2. beforeValidate and afterValidate functions

beforeValidate is called always before validation.

afterValidate is called only when there are no validation errors; the form is submited only when this function returns true.