This class can be used to render forms and to validate
and store user submits. Further types of form components can be added
by subclassing jala.Form.Component.Input.
Constructs a new Form instance
parameters
| String | name | The name of the form |
| Object | dataObj | An optional object used to retrieve values to display in the form input fields contained in this Form instance. |
methods
- setDataObject(dataObj)
- setTracker(newTracker)
- addComponent(component)
- setClassName(newClassName)
- setErrorMessage(newErrorMessage)
- hasError()
- render()
- renderAsString(param)
- validate(reqData)
- save(tracker, destObj)
- handle(reqData, destObj)
- id_macro()
properties
- String name
- Skin componentSkin
- Object components
The abstract base class for all components.
parameters
| name |
methods
- getType()
- setClassName(newClassName)
- createDomId(idPart)
- render()
- validate(tracker)
- save(destObj, val)
Constructs a new Fieldset instance
parameters
| String | name | The name of the fieldset |
methods
- addComponent(component)
- setLegend(newLegend)
- render()
- validate(tracker)
- save(tracker, destObj)
properties
Subclass of jala.Form.Component that allows rendering a skin
within a form.
parameters
| String | name | The name of the component, used as the name of the skin |
methods
- setHandler(newHandler)
- render()
Creates a new input component instance.
parameters
| String | name | Name of the component, used as name of the html control. |
methods
- require(key, val, msg)
- getRequirement(key)
- setMessage(key, msg)
- getMessage(key, defaultMsg, args)
- getLabel()
- setLabel(newLabel)
- getHelp()
- setHelp(newHelp)
- validate(tracker)
- save(tracker, destObj)
- getValue()
- setValue(destObj, value)
- render()
- id_macro()
- checkLength(reqData)
- checkRequirements(reqData)
- parseValue(reqData)
- renderControls(attr, value, reqData)
Constructs a newly created Password component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- renderControls(attr, value, reqData)
Constructs a newly created Hidden component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- render()
- renderControls(attr, value, reqData)
Constructs a new Textarea component.
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- getRows()
- setRows(newRows)
- getCols()
- setCols(newCols)
- renderControls(attr, value, reqData)
Constructs a new Date component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- setDateFormat(newDateFormat)
- renderControls(attr, value, reqData)
- checkRequirements(reqData)
- parseValue(reqData)
Constructs a new Select component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- setOptions(newOptions)
- setFirstOption(newFirstOption)
- renderControls(attr, value, reqData)
- checkRequirements(reqData)
- checkOptions(reqData)
Creates a new Radio component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- renderControls(attr, value)
- checkRequirements(reqData)
Creates a new Checkbox component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- renderControls(attr, value)
- parseValue(reqData)
- checkRequirements(reqData)
Creates a new File component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- renderControls(attr, value, reqData)
- checkRequirements(reqData, tracker)
Creates a new Image component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- checkRequirements(reqData)
Creates a new Button component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- getValue()
- setValue(newValue)
- render(attr, value, reqData)
- renderControls(attr, value)
Creates a new Submit component instance
parameters
| String | name | Name of the component, used as name of the html controls. |
methods
- renderControls(attr, value)
A generic container for error-messages and values
parameters
| reqData |
methods
- hasError()
properties
- Object reqData
- Object values
- Object errors
Readonly reference to the name of the form
Contains the default component skin
Contains a map of component objects.
The HTML renderer used by jala.Form
Constant used by require function to define that a component
should not validate if userinput is shorter than a given length.
Value: "minlength"
Constant used by require function to define that a component
should not validate if userinput exceeds a maximum length.
Value: "maxlength"
Constant used by require function to define that a component
should validate only if the user did provide input.
Value: "require"
Constant used by require function to define that a select or
radio component should validate only if the user input is contained
in the list of options provided.
Value: "checkoptions"
Constant used by require function to define that a file upload
component should validate only if the file's content type is
in the list of allowed content types provided.
Value: "contenttype"
Constant used by require function to define that an image upload
component should validate only if the image's width is less than
the value provided.
Value: "maxwidth"
Constant used by require function to define that an image upload
component should validate only if the image's width is more than
the value provided.
Value: "minwidth"
Constant used by require function to define that an image upload
component should validate only if the image's height is less than
the value provided.
Value: "maxheight"
Constant used by require function to define that an image upload
component should validate only if the image's height is more than
the value provided.
Value: "min-height"
Contains a map of all component objects of this fieldset
A map containing input from request data
A map containing parsed values (only for those fields that didn't
fail during checkRequirements method).
A map containing error messages
Methods
Sets the data object which is being edited by this form. This object
is used to get the default values when first printing the form and
- if no other object is provided - receives the changed values in save.
parameters
| Object | dataObj | The object which is being edited by this form. |
see
Returns the data object containing the values used
for rendering the form.
returns
| The data object of this jala.Form instance |
Sets the tracker object this form instance uses for collecting
error messages and parsed values.
parameters
| jala.Form.Tracker | newTracker |
Returns the tracker object this form instance uses for collecting
error messages and parsed values.
returns
| tracker object |
Returns an array containing the components
of this jala.Form instance.
returns
| The components of this jala.Form instance. |
Adds a component to this jala.Form instance
parameters
| jala.Form.Component.Input | component |
Returns true if this instance of jala.Form contains at least
one component doing a file upload.
see
Sets an extra classname for this form instance
parameters
| String | newClassName | new classname |
Returns the general error message printed above the form
if any of the components didn't validate.
returns
| error message |
Sets the general error message printed above the form if any
of the components didn't validate.
parameters
| String | newErrorMessage | error message |
Returns true if this instance of jala.Form holds a jala.Form.Tracker
instance and at least one error has been set on this tracker.
returns
| true if an error has been encountered. |
If this instance of jala.Form holds a jala.Form.Tracker
instance it returns the number of components that didn't
validate.
returns
| Number of components that didn't validate. |
Utility to set up the prototype, constructor, superclass and superconstructor
properties to support an inheritance strategy that can chain constructors and methods.
parameters
| Function | subClass | the object which inherits superClass' functions |
| Function | superClass | the object to inherit |
Parses a plain javascript object tree and configures a
new jala.Form instance according to the properties.
Propertynames are matched with constants and setter-functions,
the property "type" is used to create new component objects.
parameters
| Object | config | object tree containing config |
returns
| A newly created jala.Form instance based on the config specified |
Static validator function to test values for being a valid email address.
parameters
| String | name | name of the property being validated. |
| String | value | value in form input |
| Object | reqData | the whole request-data-object, in case properties depend on each other |
| jala.Form | formObj | instance of jala.Form |
returns
| Error message or null |
Static validator function to test values for being a valid url.
parameters
| String | name | name of the property being validated. |
| String | value | value in form input |
| Object | reqData | the whole request-data-object, in case properties depend on each other |
| jala.Form | formObj | instance of jala.Form |
returns
| Error message or null |
Renders this form including all components to response.
renders the form as a string
parameters
| param |
returns
| rendered form |
Creates a DOM identifier based on the arguments passed. The
resulting Id will be prefixed with the name of the form.
All arguments will be chained using camel casing.
returns
| The DOM Id |
Validates user input from a submitted form by calling each
component's validate method.
parameters
| Object | reqData | Optional submitted form data. If not specified req.data is used. |
returns
| tracker object with error fields set. |
Sets the parsed values on an object. By default the internally
stored tracker and data objects are used, but those may be
overridden here.
parameters
| jala.Form.Tracker | tracker | (optional) tracker object holding parsed data from form input. |
| Object | destObj | (optional) object whose values will be changed. By default the dataObj passed to the constructor or to setDataObject is used. |
Parses form input, applies check functions and stores the values
if the form does validate. Otherwise this method returns false
without saving so that the form can be reprinted with error messages.
parameters
| Object | reqData | input from form |
| Object | destObj | object whose values should be chanegd |
returns
| False if one of the checks failed, true if the element was saved correctly. |
Renders the whole form to response
Returns the id (equal to the name) of the form
returns
| The id of this Form instance |
Returns the name (equal to the id) of the form
returns
| The name of this Form instance |
Returns the class name of the form
returns
| The class name of this Form instance |
Writes the form opening tag to response
