Form.create
Form.create($formId, $formFields) -> object
Description
Create a new Form object with the given $formFields
.
Defining Form Fields
Each form field is defined as a map with these (optional) keys:
rule | Validation rule. (see Input Validation) Default: id |
tag | The HTML tag type of the field (e.g. 'textarea', 'hidden'). If not given, this will be derived from the rule . |
options | A Map or List of input options. Use this if the field type is a select, radio, or checkbox. |
label | The field label. If not given, a title case version of the field name will be used (e.g. 'favoriteColor' = 'Favorite Color') |
placeholder | Optional placeholder for text input fields (not recommended for usability reasons). |
value | Default value of the field. We recommend using the setValues method to dynamically fill in field values. |
Example
$form = Form.create('contactForm', { email: { tag: 'email' } topic: { tag: 'select' options: { bug: 'Bug Report' feature: 'Feature Request' general: 'General Feedback' } } message: { tag: 'textarea' rule: 'comment' } hiddenId: { tag: 'hidden' value: 'abc123' } })