namespace Form.Element

Description

Utilities for dealing with form controls in the DOM.

This is a collection of methods that assist in dealing with form controls. They provide ways to focus, serialize, disable/enable or extract current value from a specific control.

Note that nearly all these methods are available directly on input, select, and textarea elements. Therefore, these are equivalent:

Form.Element.activate('myfield');
$('myfield').activate();

Naturally, you should always prefer the shortest form suitable in a situation. Most of these methods also return the element itself (as indicated by the return type) for chainability.

Class methods

  • clear #

    Form.Element.clear(element) ⇒ Element
    Form#Element.clear() ⇒ Element

    Clears the contents of a text input. Returns the element.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • disable #

    Form.Element.disable(element) ⇒ Element
    Form#Element.disable() ⇒ Element

    Disables a form control, effectively preventing its value from changing until it is enabled again.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • enable #

    Form.Element.enable(element) ⇒ Element
    Form#Element.enable() ⇒ Element

    Enables a previously disabled form control.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • focus #

    Form.Element.focus(element) ⇒ Element

    Gives keyboard focus to an element. Returns the element.

  • getValue #

    Form.Element.getValue(element) ⇒ String | Array
    Form#Element.getValue() ⇒ String | Array

    Returns the current value of a form control.

    A string is returned for most controls; only multiple select boxes return an array of values.

    The global shortcut for this method is $F.

    Alias of: $F

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • present #

    Form.Element.present(element) ⇒ Element
    Form#Element.present() ⇒ Element

    Returns true if a text input has contents, false otherwise.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • select #

    Form.Element.select(element) ⇒ Element

    Selects the current text in a text input. Returns the element.

  • serialize #

    Form.Element.serialize(element) ⇒ String
    Form#Element.serialize() ⇒ String

    Returns a URL-encoded string representation of a form control in the name=value format.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

  • setValue #

    Form.Element.setValue(element, value) ⇒ Element
    Form#Element.setValue(value) ⇒ Element

    Sets value to be the value of the form control. Returns the element.

    This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.

Instance methods

  • activate #

    Form.Element#activate(element) ⇒ Element

    Gives focus to a form control and selects its contents if it is a text input.