new UWA.Controls.Form(options)
The form control is designed to create HTML form using simple API.
Available Events
Event | Description |
---|---|
onPreInject |
Triggered before inject |
onPostInject |
Triggered after inject |
onResize |
Invoked when control needs to resize |
onSubmit |
Invoked when an form submited |
onChange |
Invoked when an field state change |
Example
var prefs = new UWA.Controls.Form({
fields: [
{
type: "text",
name: "my_text",
label: "My text pref",
value: ""
},
{
type: "password",
name: "my_password",
label: "My password pref",
value: ""
},
{
type: "boolean",
name: "my_checkbox",
label: "My checkbox pref",
value: "false"
},
{
type: "hidden",
name: "my_hidden",
value: ""
},
{
type: "range",
name: "my_range",
label: "My range pref",
value: "10",
step: "5",
min: "5",
max: "15",
value: "10"
},
{
type: "list",
name: "my_list",
label: "My list",
value: "Value1",
options: [
{
label: "Label1",
value: "Value1"
},
{
label: "Label2",
value: "Value2"
},
{
label: "Label3",
value: "Value3"
}
],
value: "Value1"
}
],
events: {
onChange: function(callback, name, value) {
},
onSubmit: function(event, values) {
}
}
});
XHTML skeleton:
<form class="uwa-form" id="10">
<fieldset>
<div class="field fieldText">
<label for="m_10_my_text">My text pref:</label><span><input type="text" id="m_10_my_text" class="text" name="my_text" value=""/></span>
</div>
<div class="field fieldPassword">
<label for="m_10_my_password">My password pref:</label><span><input type="password" id="m_10_my_password" class="password" name="my_password" value=""/></span>
</div>
<div class="field fieldBoolean">
<label for="m_10_my_checkbox">My checkbox pref:</label><span><input type="checkbox" id="m_10_my_checkbox" class="boolean unchecked" name="my_checkbox"/></span>
</div>
<div class="field fieldRange">
<label for="m_10_my_range">My range pref:</label><span>
<select id="m_10_my_range" class="range" name="my_range">
<option value="5">5</option>
<option value="10" selected="selected">10</option>
<option value="15">15</option>
</select>
</span>
</div>
<div class="field fieldList">
<label for="m_10_my_list">My list:</label><span>
<select id="m_10_my_list" class="list" name="my_list">
<option value="Value1" selected="selected">Label1</option>
<option value="Value2">Label2</option>
<option value="Value3">Label3</option>
</select>
</span>
</div>
<div class="field fieldText">
<label for="m_10_json_endpoint">JSON Endpoint:</label><span><input type="text" id="m_10_json_endpoint" class="text" name="json_endpoint" value=""/></span>
</div>
<div class="field fieldText">
<label for="m_10_ajax_endpoint">Ajax Endpoint:</label><span><input type="text" id="m_10_ajax_endpoint" class="text" name="ajax_endpoint" value=""/></span>
</div>
<div class="field fieldSubmit">
<span><input type="submit" id="m_10_done" class="submit" name="done" value="Done"/></span>
</div>
</fieldset>
</form>
Parameters
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Options hash or a option/value pair. Properties
|
Extends
- UWA.Controls.Abstract
Index
Members
Methods
Members
-
id :Number
-
Current Form instance unique identifier.
Type
- Number
Methods
-
getFields()
-
Get field elements containers.
Returns
Array of Elements.
-
getField() → {Element}
-
Get field element container by name.
Returns
- Type
- Element
-
getFormValues() → {Object}
-
Get current form fields values using key/value pairs of an object.
Returns
Value hash or a name/value pair.
- Type
- Object
-
getFormValue(name) → {Object}
-
Get current form field value by name.
Parameters
Name Type Description name
String Field name
Returns
- Type
- Object
-
setFormValues(values)
-
Set current form fields values using key/value pairs of an object.
Parameters
Name Type Description values
Object Value hash or a name/value pair
-
setFormValue(name, value)
-
Set current form field value.
Parameters
Name Type Description name
String Field name
value
String Field new value
-
<static> fields.text(field, options, form) → {Object}
-
Create a new Element input type text.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type text.- Type
- Object
-
<static> fields.password(field, options, form) → {Object}
-
Create a new Element input type password.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type password.- Type
- Object
-
<static> fields.submit(field, options, form) → {Object}
-
Create a new Element input type submit.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type button.- Type
- Object
-
<static> fields.submit(field, options, form) → {Object}
-
Create a new Element input type button.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type button.- Type
- Object
-
<static> fields.reset(field, options, form) → {Object}
-
Create a new Element input type reset.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type button.- Type
- Object
-
<static> fields.boolean(field, options, form) → {Object}
-
Create a new Element input type checkbox.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
input
type checkbox.- Type
- Object
-
<static> fields.textarea(field, options, form) → {Object}
-
Create a new Element textarea.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
textarea
.- Type
- Object
-
<static> fields.range(field, options, form) → {Object}
-
Create a new Element select has range selector.
Parameters
Name Type Description field
Object field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
new Element
select
.- Type
- Object
-
<static> fields.list(field, options, form) → {Object}
-
Create a new Element select has list selector.
Parameters
Name Type Description field
Object field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
new Element
select
.- Type
- Object
-
<static> fields.checklist(field, options, form) → {Object}
-
Create a new Element with multiple checkbox.
Parameters
Name Type Description field
Object field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
new Element
- Type
- Object
-
<static> fields.html(field, options, form) → {Object}
-
Create a new Element div with html.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
new Element
div
.- Type
- Object
-
<static> fields.img(field, options, form) → {Object}
-
Create a new Element img.
Parameters
Name Type Description field
Object Field description
options
Object UWA.Controls.Form <options>
form
Object UWA.Controls.Form instance
Returns
New Element
img
.- Type
- Object