Members
(static) typeMap :Map.<string, function()>
- Description:
Registry of built-in form control types.
This map is used by FormGroup and similar helpers to resolve a control name such as
text,select, orradioselectto the matching factory function.
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
Input |
'text' | normal text input |
Textarea |
'textarea' | multi-line text input |
SelectInput |
'select' | select box with |
RadioSelectInput |
'radioselect' | radio-button group |
FormCheckInput |
'checkbox' | checkbox form control |
FormCheckInput |
'radio' | radio form control |
FormCheckInput |
'switch' | switch form control |
ComboboxInput |
'combobox' | combobox-like selection input |
Registry of built-in form control types.
This map is used by FormGroup and similar helpers to resolve a control name such as
text, select, or radioselect to the matching factory function.
Type:
- Map.<string, function()>
Methods
(static) Button(props, children) → {HTMLElement}
- Description:
Create a button control
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props |
object |
Properties
|
||||||||||||||||||||||||||||||
...props |
object | other props |
||||||||||||||||||||||||||||||
children |
object |
Returns:
a button element
- Type
- HTMLElement
(static) CheckboxInput(props) → {HTMLElement}
- Description:
Create a checkbox input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
label |
string | |
type |
string | 'checkbox' | 'radio' | 'switch' |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
reverse |
boolean | swap label left and control right |
isvalid |
boolean | |
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an checkbox control
- Type
- HTMLElement
(static) ComboboxInput(props) → {HTMLElement}
- Description:
Create a searchable input control with dropdown options. Dropdown behavior is implemented by the component and does not require Bootstrap JavaScript or Popper.
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
options |
SelectOption | |
style |
string | object | |
bsSize |
string | |
disabled |
boolean | |
...inputProps |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
input control with dropdown options
- Type
- HTMLElement
(static) ComboboxInputP(props) → {HTMLElement}
- Description:
Create a input control with dropdown options using bootstrap popper
- Source:
- Deprecated:
- Yes
Properties:
| Name | Type | Description |
|---|---|---|
options |
SelectOption | |
style |
string | |
bsSize |
string | |
disabled |
boolean | |
onitemclick |
function | onitemclick(value,selItem)
|
afteritemclick |
function | afteritemclick(event) |
...inputProps |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
input control with dropdown options
- Type
- HTMLElement
(static) FormBuilder(paramsopt) → {object}
- Description:
function FormBuilder({dom, values, rowClass="", formClass="", cols, autoRow, bsSize, id, onChange}={})
A FormController with convenient features for creating forms quickly. It creates rows, adds form groups, keeps the DOM tree, manages validation, and updates values from input events.
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
dom |
HTMLElement | form DOM container |
values |
object | current values from the controller |
rowClass |
string | default CSS class for rows |
formClass |
string | CSS class applied to the form element |
cols |
string | default columns setting for inputs |
autoRow |
boolean | automatically create rows when columns exceed 12 |
bsSize |
string | default Bootstrap size for children controls |
id |
string | form id prefix used for generated input ids |
onChange(func) |
function | subscribe to changed values |
add(args) |
function | add a form group to the current or new row. |
addGroup(args) |
function | add a prepared form group directly. |
addRow(arg) |
function | create a new row or end the current one with |
addChildren(...children) |
function | add HTMLElements to dom |
getFormValid() |
function | return true if all validation checks pass |
setValues(values) |
function | update a set of field values in the form |
groupIdByName(name) |
function | return generated group id |
inputIdByName(name) |
function | return generated control id |
labelIdByName(name) |
function | return generated label id |
Example
const fb = FormBuilder({
formClass: 'row g-2 m-2 p-2',
autoRow: true,
});
fb.add({ name: 'name', label: 'Name', type: 'text' });
fb.add({ name: 'pw', label: 'Password', type: 'password' });
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<optional> |
{}
|
controller configuration Properties
|
Returns:
- Type
- object
(static) FormCheckInput(props) → {HTMLElement}
- Description:
Create a checkbox input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
label |
string | |
type |
string | 'checkbox' | 'radio' | 'switch' |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
reverse |
boolean | swap label left and control right |
isvalid |
boolean | |
oninput |
function | oninput(event) called on value changed |
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an checkbox switch or radio control
- Type
- HTMLElement
(static) FormControl(props) → {HTMLElement}
- Description:
Create a form control
- Source:
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props |
object |
Properties
|
Returns:
div element
- Type
- HTMLElement
(static) FormController(paramsopt) → {object}
- Description:
function FormController({values})
Create a simple controller to collect and synchronize form values. The controller stores the current values in
self.values, emits change events, and provides helper methods for generated input controls.
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
values |
object | key/value object with the current input values |
onChange(func) |
function | subscribe to value changes |
offChange(func) |
function | unsubscribe from value changes |
emitChange(name, |
function | value, event) - notify all listeners |
handleInput(event) |
function | default input handler for form controls |
args(args) |
function | return the basic FormGroup arguments |
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<optional> |
{}
|
controller configuration Properties
|
Returns:
- Type
- object
(static) FormGroup(props) → {HTMLElement}
- Description:
Create a form group, a formated combination of label ind input
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
label |
label | text for the label |
input |
object | input element |
style |
string | |
class |
string | |
inputClass |
string | |
cols |
string | |
col |
string | |
separated |
boolean | |
...inputProps |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object | |
...children |
array |
Returns:
div element
- Type
- HTMLElement
(static) FormLabel(props) → {HTMLElement}
- Description:
Create a form label
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
col |
string | number for the col-form-label class |
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an label element
- Type
- HTMLElement
(static) Input(props) → {HTMLElement}
- Description:
Create a input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
isvalid |
boolean | |
oninput |
function | oninput(event) called on value changed
|
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an input control element
- Type
- HTMLElement
(static) RadioInput(props) → {HTMLElement}
- Description:
Create a radio input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
label |
string | |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
reverse |
boolean | swap label left and control right |
isvalid |
boolean | |
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an radio control
- Type
- HTMLElement
(static) RadioSelectInput(props) → {HTMLElement}
- Description:
Create a group of radio buttons as input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
options |
SelectOption | |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
inline |
boolean | |
disabled |
boolean | |
isvalid |
boolean | |
oninput |
function | oninput(event) called on value changed
|
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an input control element
- Type
- HTMLElement
(static) SelectInput(props) → {HTMLElement}
- Description:
Create a select input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
options |
SelectOption | |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
isvalid |
boolean | |
oninput |
function | oninput(event) called on value changed
|
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an select input control element
- Type
- HTMLElement
(static) SwitchInput(props) → {HTMLElement}
- Description:
Create a switch control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
label |
string | |
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
reverse |
boolean | swap label left and control right |
isvalid |
boolean | |
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an switch control
- Type
- HTMLElement
(static) Textarea(props) → {HTMLElement}
- Description:
Create a textarea input control
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
bsSize |
string | |
class |
string | |
style |
string | |
id |
string | |
value |
string | |
disabled |
boolean | |
isvalid |
boolean | |
oninput |
function | oninput(event) called on value changed
|
...props |
object | other props |
Parameters:
| Name | Type | Description |
|---|---|---|
props |
object |
Returns:
an textarea input control element
- Type
- HTMLElement