$b.getForm: Telegraph - Bicycle Form Handler
Telegraph is an easy form manipulation and submission handler.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Selects the form and fills an array with it's children elements excluding buttons.
|
| Method Attributes | Method Name and Description |
|---|---|
|
field(name)
Fills the form fields array with specific named field(s).
|
|
|
getTypes(buttons)
Returns an object with elements names sorted by type.
|
|
|
fieldsByType(type)
Returns an object containing field:value pairs by field specified type.
|
|
|
value(v)
Sets or gets the value of a field.
|
|
|
serialize(o)
Builds an object from the fields array excluding empty fields.
|
|
|
toQuery(d)
Converts fields name and value to a query string.
|
|
|
send(url, m, fn)
Shortcut to send form data via AJAX.
|
|
|
ajax(opts)
Initializes a new ajax call and send form data.
|
|
|
preventSubmit(el)
Prevents submitting of form and other default buttons behaviours.
|
Namespace Detail
$b.getForm
Selects the form and fills an array with it's children elements excluding buttons.
The returned object has some static properties:
- .f : reference to the form DOM element
- .fId : id of the form element
- .fields : an array of form fields
- .buttons : an object containing as properties .submits .resets .buttons and as values an array of Form elements references
- Parameters:
- {String} id
- Id assigned to the form
- Returns:
- {Object} Returns a new Form Object
Method Detail
{Object}
field(name)
Fills the form fields array with specific named field(s).
- Parameters:
- {String} name
- Name attribute of the field(s)
- Returns:
- {Object} Returns the form object
{Object}
getTypes(buttons)
Returns an object with elements names sorted by type.
$b.getForm("myForm").getTypes();
//returns { "text" : ["field1","field2"], "select-one" : ["select1","select2"]}
- Parameters:
- {Bool} buttons Optional
- Set to
trueto add buttons elements $b.getForm
- Returns:
- {Object} Returns an object with elements sorted by type
fieldsByType(type)
Returns an object containing
field:value pairs by field specified type. - Parameters:
- {String} type
- Type can be:
text,textarea,select-one,checkbox,radio,buttons
Sets or gets the value of a field.
- Parameters:
- {String} v Optional
- Set the field value
- Returns:
- {Object|String|Array} If param
vis set returns the form object, else returns the field value or an array of checked fields values (for checkboxes)
{Object}
serialize(o)
Builds an object from the fields array excluding empty fields.
- Parameters:
- {String} o Optional
- an object to be merged to the fields' serialization
- Returns:
- {Object} Returns an object with pairs
fieldName : fieldValue(StringorArray)
- See:
- #value
{String}
toQuery(d)
Converts fields name and value to a query string.
- Parameters:
- {String} d Optional
- Delimiter to use for joined array values on fields with same name. Defaults to ":".
- Returns:
- {String} Returns a query string of not empty fields:
fieldName=fieldValue&...
- See:
- #serialize
{Object}
send(url, m, fn)
Shortcut to send form data via AJAX.
- Parameters:
- {String} url
- Url to processing script
- {String} m Optional
- Method to send data: "
POST" or "GET". Defaults to "POST". - {Function} fn Optional
- A callback function to launch on AJAX complete
- Returns:
- {Object} Returns the Form Object
- See:
- #toQuery
{Object}
ajax(opts)
Initializes a new ajax call and send form data.
- Parameters:
- {Object} opts Optional
- An object with options:
url{String} Url to processing script
method{String} Method to send data: "POST" or "GET". Defaults to "POST".
data{Object} addictional data to send
onComplete{Function} A callback function to launch on AJAX complete
- Returns:
- {Object} Returns the Form Object
- See:
- #serialize
{Object}
preventSubmit(el)
Prevents submitting of form and other default buttons behaviours.
- Parameters:
- {Object} el Optional
- Also prevent the behaviours of these optional elements (see $b.add)
- Returns:
- {Object} Returns the Form Object