# Class: Input

## jala.Form.Component.Input(name)

Instances of this class represent a single form input field.

## Constructor

#### new Input(name)

Creates a new input component instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | Name of the component, used as name of the html control.

Source:
  - jala/code/Form.js, line 1129

### Members

#### getter :function

The getter function for this component. If set, the function is called to retrieve the original value of the field. When called, the scope is set to the data object and the name of the element is the sole argument.

##### Type:

- function

Source:
  - jala/code/Form.js, line 1262
See:
  - #getValue

#### setter :function

The setter function for this component. If set, the function is called to store the new value of the field. When called, the scope is set to the data object and the name and value of the element are provided as arguments.

##### Type:

- function

Source:
  - jala/code/Form.js, line 1285
See:
  - #setValue

#### validator :function

The validator function for this component. If set, the function is called with the scope set to the data object and with four arguments:
- the name of the element
- the parsed value of the element if all requirements have been fulfilled. E.g., for a date editor, the parsed value would be a date object.
- the map containing all user inputs as string (req.data)
- the form object

##### Type:

- function

Source:
  - jala/code/Form.js, line 1310
See:
  - #validate

#### (inner) help :String

Private field containing the help text of this component

##### Type:

- String

Source:
  - jala/code/Form.js, line 1152

#### (inner) label :String

Private field containing the label of this component

##### Type:

- String

Source:
  - jala/code/Form.js, line 1146

#### (inner) messages

Private map containing messages to use when a requirement is not met

Source:
  - jala/code/Form.js, line 1140

#### (inner) requirements

Private map containing the requirements that need to be met

Source:
  - jala/code/Form.js, line 1135

### Methods

#### checkLength(reqData)

Checks user input for maximum length, minimum length and require if the corresponding options have been set using the require method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`reqData` | Object | request data

Source:
  - jala/code/Form.js, line 1604
See:
  - #require

##### Returns:

String containing error message or null if everything is ok.

#### checkRequirements(reqData)

Checks user input against options set using the require method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`reqData` | Object | request data

Source:
  - jala/code/Form.js, line 1634
See:
  - #checkLength
  - #require

##### Returns:

String containing error message or null if everything is ok.

#### class_macro()

Renders this component's class name. Note that this is just the class name that has been explicitly assigned using setClassName.

Source:
  - jala/code/Form.js, line 1570
See:
  - #setClassName

#### controls_macro()

Renders the control(s) of this component

Source:
  - jala/code/Form.js, line 1504

#### error_macro()

Renders this component's error message (if set) directly to response

Source:
  - jala/code/Form.js, line 1518

#### getControlAttributes()

Creates a new attribute object for this element.

Source:
  - jala/code/Form.js, line 1584

##### Returns:

Object with properties id, name, class

#### getHelp()

Returns the help text set for this component.

Source:
  - jala/code/Form.js, line 1241

##### Returns:

help text

#### getLabel()

Returns the label set for this component.

Source:
  - jala/code/Form.js, line 1223

##### Returns:

label

#### getMessage(key, defaultMsg, args)

Returns a specific message for a config element.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | The key of the message as defined by the constants in jala.Form.* (e.g. "require", "maxlength", "minlength" ...
`defaultMsg` | String | the message to use when no message was defined.
`args` | Object | One or more arguments passed to the gettext message processor which will replace {0}, {1} etc.

Source:
  - jala/code/Form.js, line 1210

##### Returns:

rendered message

#### getRequirement(key)

Returns the requirement value for a given key.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | String defining the type of requirement, constants in jala.Form may be used.

Source:
  - jala/code/Form.js, line 1183

#### getValue()

Retrieves the property which is edited by this component.

- If no getter is given, the method returns the primitive property of the data object with the same name as the component.
- If a getter function is defined, it is executed with the scope of the data object and the return value is used as default value. The name of the component is passed to the getter function as an argument.

Source:
  - jala/code/Form.js, line 1384

##### Returns:

The value of the property

#### help_macro()

Renders this component's help text, if set.

Source:
  - jala/code/Form.js, line 1534

#### id_macro()

Renders this component's id

Source:
  - jala/code/Form.js, line 1543
See:
  - jala.Form#createDomId

#### label_macro()

Renders this component's label.

Source:
  - jala/code/Form.js, line 1526

#### name_macro()

Renders this component's name

Source:
  - jala/code/Form.js, line 1551

#### parseValue(reqData)

Parses the string input from the form and creates the datatype that is edited with this component. For the input component this method is not of much use, but subclasses that edit other datatypes may use it. For example, a date editor should convert the user input from string to a date object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`reqData` | Object | request data

Source:
  - jala/code/Form.js, line 1648

##### Returns:

parsed value

#### render()

Renders this component including label, error and help messages directly to response.

Source:
  - jala/code/Form.js, line 1422

#### renderControls(attr, value, reqData)

Renders the html form elements to the response. This method shall be overridden by subclasses of input component.

##### Parameters:

Name | Type | Description
--- | --- | ---
`attr` | Object | Basic attributes for the html form elements.
`value` | Object | Value to be used for rendering this element.
`reqData` | Object | Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured.

Source:
  - jala/code/Form.js, line 1660

#### renderError()

If the error tracker holds an error message for this component, it is wrapped in a div-tag and returned as a string.

Source:
  - jala/code/Form.js, line 1449

##### Returns:

Rendered string

#### renderHelp()

If this component contains a help message, it is wrapped in a div-tag and returned as a string.

Source:
  - jala/code/Form.js, line 1479

##### Returns:

The rendered help message

#### renderLabel()

Returns the rendered label of this component

Source:
  - jala/code/Form.js, line 1465

##### Returns:

The rendered label of this component

#### render_macro()

Renders this component including label, error and help messages directly to response

Source:
  - jala/code/Form.js, line 1496

#### require(key, val, msg)

Sets a requirement for this component. If function is called without arguments, jala.Form.REQUIRE is set to true.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | String defining the type of requirement, constants in jala.Form may be used.
`val` | Object | Value of the requirement.
`msg` | String | Optional error message if requirement is not fulfilled.

Source:
  - jala/code/Form.js, line 1164

#### save(tracker, destObj)

Saves the parsed value using setValue.

##### Parameters:

Name | Type | Description
--- | --- | ---
`tracker` | jala.Form.Tracker | Tracker object collecting request data, error messages and parsed values.
`destObj` | Object | (optional) object whose values will be changed.

Source:
  - jala/code/Form.js, line 1366
See:
  - #setValue

#### setHelp(newHelp)

Sets the help text for this component

##### Parameters:

Name | Type | Description
--- | --- | ---
`newHelp` | String | new help text

Source:
  - jala/code/Form.js, line 1249

#### setLabel(newLabel)

Sets the label for this component

##### Parameters:

Name | Type | Description
--- | --- | ---
`newLabel` | String | new label

Source:
  - jala/code/Form.js, line 1231

#### setMessage(key, msg)

Sets a custom error message

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | String defining the type of requirement, constants in jala.Form may be used.
`msg` | String | Error message

Source:
  - jala/code/Form.js, line 1193

#### setValue(destObj, value)

Sets a property of the object passed as argument to the given value.
- If no setter is set at the component, the primitive property of the data object is changed.
- If a setter function is defined it is executed with the data object as scope and with the name and new value provided as arguments
- If the setter is explicitly set to null, no changes are made at all.

##### Parameters:

Name | Type | Description
--- | --- | ---
`destObj` | Object | (optional) object whose values will be changed.
`value` | Object | The value to set the property to

Source:
  - jala/code/Form.js, line 1406
See:
  - jala.Form#setter

##### Returns:

True in case the update was successful, false otherwise.

#### type_macro()

Renders this component's type

Source:
  - jala/code/Form.js, line 1559

#### validate(tracker)

Validates the input provided to this component. First, checkRequirements is called. If no error occurs, the input is parsed using parseValue and passed on to the validator function.

##### Parameters:

Name | Type | Description
--- | --- | ---
`tracker` | jala.Form.Tracker | Tracker object collecting request data, error messages and parsed values.

Source:
  - jala/code/Form.js, line 1337
See:
  - #checkRequirements
  - #parseValue