import InputElement from 'elementify/lib/elements/inputelement.js'
InputElement
Extends:
InputElement is the common basic class wrapping all vanilla HTML inputs. It provides all properties and method to :
- get/set Element value
- reset Element value
- validate Element value
Test:
Constructor Summary
Private Constructor | ||
private |
constructor(node: Element, options: KeyValueObject): InputElement InputElement constructor Node and options are passed through Element call. |
version 1.0.0 since 1.0.0 |
Member Summary
Public Members | ||
public get |
Dirty state |
version 1.0.0 since 1.0.0 |
public get |
Fetch validation errors |
version 1.0.0 since 1.0.0 |
public get |
Get a unique name
|
version 1.0.0 since 1.0.0 |
public get |
Export rules set on the Element |
version 1.0.0 since 1.0.0 |
public set |
Import rules set on the Element |
version 1.0.0 since 1.0.0 |
public get |
Get standardized lowercased type attribute |
version 1.0.0 since 1.0.0 |
public set |
Set input type attribute |
version 1.0.0 since 1.0.0 |
public get |
Get value |
version 1.0.0 since 1.0.0 |
public set |
Set value |
version 1.0.0 since 1.0.0 |
Private Members | ||
private |
Errors after validation |
since 1.0.0 |
private |
Rules for validation |
since 1.0.0 |
Method Summary
Public Methods | ||
public |
label(t: string, o: KeyValueObject): HtmlElement Returns a label HtmlElement linked to this inputElement |
version 1.0.0 since 1.0.0 |
public |
rule(name: string, pattern: string | RegExp | CSSSelector | InputRuleCallback, message: string, evaluate: boolean): this Add a validation rule. |
version 1.0.0 since 1.0.0 |
public |
tooltip(t: $type, o: KeyValueObject): HtmlElement Returns a tooltip HtmlElement linked to this inputElement |
version 1.0.0 since 1.0.0 |
public |
Get/Set value. |
version 1.0.0 since 1.0.0 |
public |
Validate the field against the rules. |
version 1.0.0 since 1.0.0 |
Private Constructors
private constructor(node: Element, options: KeyValueObject): InputElement version 1.0.0 since 1.0.0 source
InputElement constructor Node and options are passed through Element call.
If the Element have required or pattern atributes, validation rules will be automatically set accordingly.
Params:
Name | Type | Attribute | Description |
node | Element | Input element |
|
options | KeyValueObject | Options for the InputElement Specific keys are :
|
Test:
Public Members
public get dirty: boolean version 1.0.0 since 1.0.0 source
Dirty state
Will be true
if field value/state have changed
false
otherwise
public get name: string version 1.0.0 since 1.0.0 source
Get a unique name
name
attribute valueid
attribute value if name not set- A random unique id if both name and value are not set
public get rules: InputValidationRules version 1.0.0 since 1.0.0 source
Export rules set on the Element
Test:
public set rules: InputValidationRules version 1.0.0 since 1.0.0 source
Import rules set on the Element
public get value: boolean | string | undefined version 1.0.0 since 1.0.0 source
Get value
It normalizes the behaviour for boolean inputs (radio & checkbox) :
- If no value attribute is set, it will return
true
orfalse
- If a value attribute is set, it will return undefined and will be skipped in fields list if not checked or returns its value otherwise.
Test:
TODO:
- - Add more casting (all values are considered as string when extracted)
Private Members
Public Methods
public label(t: string, o: KeyValueObject): HtmlElement version 1.0.0 since 1.0.0 source
Returns a label HtmlElement linked to this inputElement
Params:
Name | Type | Attribute | Description |
t | string | Text for label |
|
o | KeyValueObject | Options for HtmLElement |
public rule(name: string, pattern: string | RegExp | CSSSelector | InputRuleCallback, message: string, evaluate: boolean): this version 1.0.0 since 1.0.0 source
Add a validation rule. Some presets are available :
required
: Value must be not empty. Add arequired
attribute to the Elementsameas
: Value must be the same than another field. You must provide a CSS Selector to query this field as second argumentint
: Strict integer (only numbers)number
: Decimal number (with dot). Change Element type attribute tonumber
email
: E-mail pattern. Change Element type attribute toemail
For custom error messages when validating through browser or programmatically, you can set the title attribute of the InputElement or provide a message when creating rule.
Params:
Name | Type | Attribute | Description |
name | string | Name of the rule (preset or custom) |
|
pattern | string | RegExp | CSSSelector | InputRuleCallback |
|
Presets will usually don't require this value
|
message | string |
|
A message linked to a non validated rule can be store here |
evaluate | boolean |
|
If |
Return:
this | Chainable |
Test:
TODO:
- Add more presets
public tooltip(t: $type, o: KeyValueObject): HtmlElement version 1.0.0 since 1.0.0 source
Returns a tooltip HtmlElement linked to this inputElement
Params:
Name | Type | Attribute | Description |
t | $type | Text for tooltip |
|
o | KeyValueObject | Options for HtmLElement |
public val(v: number | string): this | boolean | string | undefined version 1.0.0 since 1.0.0 source
Get/Set value. It's a chainable alias for the getter/setter properties