Version: v0.7.1 - Beta.  We welcome contributors & feedback.

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:

ruleValidation rule. (see Input Validation) Default: id
tagThe HTML tag type of the field (e.g. 'textarea', 'hidden'). If not given, this will be derived from the rule.
optionsA Map or List of input options. Use this if the field type is a select, radio, or checkbox.
labelThe field label. If not given, a title case version of the field name will be used (e.g. 'favoriteColor' = 'Favorite Color')
placeholderOptional placeholder for text input fields (not recommended for usability reasons).
valueDefault 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',
    },
})

See Also

See Also