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:

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:
See:

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:
See:

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:
    See:

    (inner) help :String

    Private field containing the help text of this component
    Type:
    • String
    Source:

    (inner) label :String

    Private field containing the label of this component
    Type:
    • String
    Source:

    (inner) messages

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

    (inner) requirements

    Private map containing the requirements that need to be met
    Source:

    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:
    See:
    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:
    See:
    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:
    See:

    controls_macro()

    Renders the control(s) of this component
    Source:

    error_macro()

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

    getControlAttributes()

    Creates a new attribute object for this element.
    Source:
    Returns:
    Object with properties id, name, class

    getHelp()

    Returns the help text set for this component.
    Source:
    Returns:
    help text

    getLabel()

    Returns the label set for this component.
    Source:
    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:
    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:

    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:
    Returns:
    The value of the property

    help_macro()

    Renders this component's help text, if set.
    Source:

    id_macro()

    Renders this component's id
    Source:
    See:

    label_macro()

    Renders this component's label.
    Source:

    name_macro()

    Renders this component's name
    Source:

    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:
    Returns:
    parsed value

    render()

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

    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:

    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:
    Returns:
    Rendered string

    renderHelp()

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

    renderLabel()

    Returns the rendered label of this component
    Source:
    Returns:
    The rendered label of this component

    render_macro()

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

    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:

    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:
    See:

    setHelp(newHelp)

    Sets the help text for this component
    Parameters:
    Name Type Description
    newHelp String new help text
    Source:

    setLabel(newLabel)

    Sets the label for this component
    Parameters:
    Name Type Description
    newLabel String new label
    Source:

    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:

    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:
    See:
    Returns:
    True in case the update was successful, false otherwise.

    type_macro()

    Renders this component's type
    Source:

    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:
    See: