Manual Reference Source Test
import FormElement from 'elementify/lib/elements/formelement.js'
public class | version 1.0.0 | since 1.0.0 | source

FormElement

Extends:

elements/htmlelement~HtmlElement → FormElement

A FormElement instance node may contains only <form> Element.

Its main purpose is to provide an easy way to validate a whole form and prepare data for submission

Test:

TODO:

  • - Add support for binary data

Constructor Summary

Private Constructor
private

The form constructor

version 1.0.0 since 1.0.0

Member Summary

Public Members
public get

Form data as an ObjectArray object

version 1.0.0 since 1.0.0
public set

datas: keyValueObject | ObjectArray

Import data into form fields from a KeyValueObject or an ObjectArray object

version 1.0.0 since 1.0.0
public get

Dirty state of the form.

version 1.0.0 since 1.0.0
public get

Fetch validation errors

version 1.0.0 since 1.0.0
public get

Returns a Collection of all fields.

version 1.0.0 since 1.0.0
public get

Form data as a FormData object

version 1.0.0 since 1.0.0
public get

Data of the form serialized in urlEncode standard.

version 1.0.0 since 1.0.0
public get

Data of the form returned as a JSON string

version 1.0.0 since 1.0.0
public set

Import data into form fields from JSON

version 1.0.0 since 1.0.0
public get

Data of the form serialized in urlEncode standard.

version 1.0.0 since 1.0.0
Private Members
private

Errors after validation

since 1.0.0

Method Summary

Public Methods
public

Returns a field by its name

version 1.0.0 since 1.0.0
public

Validate the form by validating each field rule.

version 1.0.0 since 1.0.0

Private Constructors

private constructor(node: Element, options: KeyValueObject): FormElement version 1.0.0 since 1.0.0 source

The form constructor

Params:

NameTypeAttributeDescription
node Element

Form Element

options KeyValueObject
  • optional
  • default: {}

Return:

FormElement

Test:

See:

Public Members

public get datas: ObjectArray version 1.0.0 since 1.0.0 source

Form data as an ObjectArray object

public set datas: keyValueObject | ObjectArray version 1.0.0 since 1.0.0 source

Import data into form fields from a KeyValueObject or an ObjectArray object

public get dirty: boolean version 1.0.0 since 1.0.0 source

Dirty state of the form. Set by fetching all dirty properties of the form's fields.

Test:

public get errors: Object version 1.0.0 since 1.0.0 source

Fetch validation errors

Test:

public get fields: Collection version 1.0.0 since 1.0.0 source

Returns a Collection of all fields. The collection is dynamic and regenerated by querying. To ignore an input Element, just add class 'form-ignore' to it.

Test:

public get formData: FormData version 1.0.0 since 1.0.0 source

Form data as a FormData object

Test:

public get formUrlEncode: string version 1.0.0 since 1.0.0 source

Data of the form serialized in urlEncode standard. This string is suitable for a form-url-encoded data submission

Test:

public get json: string version 1.0.0 since 1.0.0 source

Data of the form returned as a JSON string

Test:

public set json: string version 1.0.0 since 1.0.0 source

Import data into form fields from JSON

Throw:

TypeError

public get urlEncode: string version 1.0.0 since 1.0.0 source

Data of the form serialized in urlEncode standard. This string is suitable for a query part or an URI.

Test:

Private Members

private _errors: ObjectArray since 1.0.0 source

Errors after validation

Public Methods

public field(f: string): InputElement version 1.0.0 since 1.0.0 source

Returns a field by its name

Params:

NameTypeAttributeDescription
f string

Field name

Return:

InputElement

Test:

public validate(): Boolean version 1.0.0 since 1.0.0 source

Validate the form by validating each field rule. The class field-validate is added to validated fields Element otherwise class field-not-validate is added to the Element

Return:

Boolean

trueif validation is OK, false otherwise

Test:

See: