FormController

A FormController manages a form's state. Its constructor takes an options object comprised of FormField objects.

PropertyTypeDefaultValueDescription
defaultValueanynullOptional - The field's initial value.
validation(value) => boolean(state) => trueOptional - method that takes the field's data value and returns a boolean, determining whether the field is valid.
hidden(state) => boolean(state) => falseOptional - a boolean (or method that takes the Form's state and returns a boolean) determining whether the field should be hidden.
requiredboolean or (state) => booleanfalseOptional - a boolean (or method that takes the Form's state and returns a boolean) determining whether the field is required.
errorTextstring or (value) => stringnullOptional - a string (or method that takes the field's value and returns a string) to show when the field is invalid.

Each object will be stored in state under data as an object with the following properties:

PropertyTypeDescription
valueanyThe field's current value - either its defaultValue or the value set using the controller's setValue method.
validbooleanWhether the field's value has passed its validation check.
errorTextstringThe field's current error text, if any, depending on its value.
requiredbooleanWhether the field is currently required.
hiddenbooleanWhether the field is currently hidden.

The FormController itself has the following properties and methods:

PropertyTypeDescription
fieldsobjectThe controller's current fields.
dataobjectThe controller's current data, with a state for each field.
readybooleanWhether the form is complete. A form is complete when each of its required, non-hidden data states are valid.
MethodDescription
setValue(id, value)Set the value of the given field.

Example: