Form Class

Used to create a container with form inputs

Constructors

Form( parent, config )
Used to instantiate this class
parentDOM element in which to render this component
configConfiguration settings (optional). See config options for more information.

Config Options

onsubmit
items
An array of items that make up the form (e.g. form inputs and labels).
buttons
An array of buttons that will be placed at the bottom of the form (e.g. submit, cancel, reset). Example:
            buttons: [
                {
                    name: "Submit",
                    onclick: function(){
                        var values = form.getData();
                        //TODO: validate form data
                    }
                },
                {
                    name: "Reset",
                    onclick: function(){
                        form.clear();
                    }
                }
            ]
        
style
Style for individual elements within the component. Note that you can provide CSS class names instead of individual style definitions.

Events

onChange( input, value )
Called whenever a field changes value in the form
onResize( )
Called whenever the form is resized

Public Methods

resize( )
Used to update the layout of all the elements in this component
getForm( )
Returns the "form" element underpinning this component
reset( )
Resets all inputs in the form to thier original values.
clear( )
Clears all values in the form.
getData( )
Returns the values for all the form inputs in JSON notation. Note that if the form has multiple inputs with the same name, the associated value will be an array. You can test whether the value is an array using the "instanceof Array" operator.
getFormData( )
Returns the values for all the form inputs as a FormData object
addButton( name, enabled, onclick )
Used to add a button to the bottom of the form
getButton( name )
Returns a button found at the bottom of the form
nameName of the button (input.name)
getButtons( )
Returns all the buttons found at the bottom of the form as an array
getGroups( )
Returns an array of groups found in the form. Each entry in the array has a name and custom methods for the group.
showGroup( name )
Used to display a hidden group.
hideGroup( name )
Used to hide a group box.
enableField( name )
Used to enable a form input. Returns true if the field was found and is enabled.
disableField( name )
Used to disable a form input. Returns true if the field was found and is disabled.
hideField( name )
Used to hide a form input. Returns true if the field was found and hidden from view.
showField( name )
Used to unhide a form input. Returns true if the field was found and is visible.
showError( errorMessage, field )
Renders a popup error message over a given field
hideError( field )
Hides a popup error message over a given field
getValue( name )
Returns the value for an input in the form.
setValue( name, value, silent )
Used to set the value for an input in the form.
nameInput name or label associated with the input.
valueA value for the input.
silentBy default, if the input value is changed, it will fire. the onChange event. When silent is set to true, the input will NOT fire the onChange event. This parameter is optional.
findField( name )
Used to find a row in the form.
nameInput name or label associated with the input.