Constructor
new Form(data, indexopt)
Create Form.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | An object defining the properties of a Form.
Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
index |
number |
<optional> |
Defines index of the current form. |
Members
sectionContainer
Get section container, that is this.baseForm which has been either passed upon initialization or created automatically.
Methods
addQuery(queryItem) → {QueryItem|false}
Add query to DOM on this form
Parameters:
| Name | Type | Description |
|---|---|---|
queryItem |
QueryItem | A QueryItem to be logged in the internal structure and appended to the form element. |
Returns:
- Returns the registerd QueryItem or false if no QueryItem was passed.
- Type
- QueryItem | false
createQuery(queryData) → {QueryItem|false}
Create a new query (QueryItem + QueryDataBlock) on this form
Parameters:
| Name | Type | Description |
|---|---|---|
queryData |
QueryDataBlock | Object | A QueryDataBlock to be used with the new QueryItem or an Object convertible to QueryDataBlock. |
- Source:
- See:
-
- QueryDataBlock for more information on the required Object structure.
Returns:
- Returns the newly created QueryItem or false if no QueryData was passed.
- Type
- QueryItem | false
createSubmit() → {dom}
Creates form submit tag.
Returns:
- The newly created form DOM submit button.
- Type
- dom
createTitle() → {dom}
Creates form title tag.
Returns:
- The newly created form DOM title tag.
- Type
- dom
getFirstInvalidItem(passAll) → {Object|null}
Get first invalid input item.
Parameters:
| Name | Type | Description |
|---|---|---|
passAll |
boolean | If set to false it won't go through each item and break on first error found. |
Returns:
- An object with the first invalid InputItem from the beginning and numeric queryIndex, or null if all items are valid.
- Type
- Object | null
isValid() → {boolean}
Checks whether the form is valid or not.
Returns:
- Return true if all input data is valid, false if not.
- Type
- boolean
newQueryItem(queryData) → {QueryItem|false}
Adds a new QueryItem to the Form
Parameters:
| Name | Type | Description |
|---|---|---|
queryData |
QueryDataBlock | Object | A QueryDataBlock to be used with the new QueryItem or an Object convertible to QueryDataBlock, @see QueryDataBlock. |
Returns:
- Returns the registerd QueryItem or false if no QueryItem was passed.
- Type
- QueryItem | false
queryValues() → {Array.<string>}
Returns an array of form input values.
Returns:
- Array of values for each registered each QueryItem.
- Type
- Array.<string>
serialize() → {string}
Serializes form data and returns them in a string.
Returns:
- Serialized Form data.
- Type
- string
setOnSubmitEvent(call) → {boolean}
Define what should be called upon submitting the form using submit event.
Once the callback function is called it will receive the event via its parameter and this set to the instance of this Form class.
Always prevents default form submit event.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
function | A function that should be called upon submitting the form. |
Returns:
- True if this.baseForm and call was defined and event set up, false if not.
- Type
- boolean
showSubmitSummary(keepFormopt) → {Form}
Show a simple built-in form submit summary in place of the original form.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
keepForm |
boolean |
<optional> |
If set to true the form will not be remove from the DOM and the submit summary will display below it. |
Returns:
- Instance of this Form.
- Type
- Form
submitProcess() → {boolean}
Walks trhough the full submit form process taking care of corrections if allowed and posting data using POST method to a specified url.
Returns:
- True if submit process completed or false if there were validation issues and corrections were allowed.
- Type
- boolean
validate() → {boolean}
Validates all form fields by calling each QueryItem validation.
In addition scrolls to the first invalid element if there is such.
Returns:
- Returns true if all field are valid, false if not.
- Type
- boolean
validationSummary() → {object}
Gets validation summary object containing an array of relevant form submit data.
Returns:
- An object with the following structure: { items: [allValid, title, subtitle, type, queryValues], itemsLength }
- Type
- object