The Form class converts objects into a structure that can be run through a template and converted into an HTML form.


new Form(objType, obj, exclude)

This returns a new form object that DART's templates can render as an HTML form.

Name Type Description
objType string

The name of the class this form will represent. For example, AppSetting, RemoteRepository, etc. These are generally subclasses of PersistentObject.

obj PersistentObject | object

The object from which you want to create a form. This class will generate the form fields for all of the attributes of obj, except those specified in the exclude param. The obj param should be an instance of an object derived from {@ref PersistentObject}, but you can create an empty form by passing in an empty object like so:

var myForm = new Form('Object', {}); .
exclude Array.<string>

A list of object attributes to exclude from the form. The form will not include fields for these items. You don't need to include the 'id' or 'userCanDelete' attributes in this list.

Default Value:
  • ['errors', 'help', 'required']



This creates a single field with the given name and value and adds it to the fields property of the form.

Name Type Description
name string

The name of the field to add.



This creates fields for each attribute of form.obj, including setting the name, id, value, label, error message and help text of each item.

The label and help text come from the locale file for each specific language. To set the label, add an entry to to the locale file named _label. To set the help text, add an entry to the locale file named _help. For example:

{ "MyClass_surname_label": "Surname", "MyClass_surname_help": "Enter your family name.", }

This does not set the choices for select lists or checkbox groups. You'll have to do that yourself after the form is created.

This method does not determine which HTML control will render on the form. Since that is a layout issue, you can specify that in your form template.


castNewValueToType(oldValue, formValue) → {string|number|boolean}

This casts a string value from a form to the correct type required by the underlying object, including strings, numbers and booleans.

Name Type Description
oldValue string | number | boolean

The original value, read from the property of Form.obj.

formValue string

The value read from the HTML form, which will always be a string.


hasErrors() → {boolean}

Returns true if the form contains errors. Check this after calling parseFromDOM to see if there were any validation errors.



This updates all of the values of Form.obj based on what the user entered in the HTML form. Note that because there are no PUT or POST operations in DART, this method reads directly from the HTML form on the current page, casting number and boolean values to the correct types.

This also sets the values of the Form.changed object, which shows the old and new values of each property that the user changed.

This returns nothing. Check the values of Form.obj and Form.changed after calling this. The controller classes call this method when users submit forms.



This sets the errors on the form, based on errors flagged in the {@ref PersistentObject} Form.obj.errors.