vUX / FormComponents / v4.1.0
Six builders that hide a real <input> and draw a widget in front of it.
The native element stays the source of truth: your form, your validation, your submit.
Each widget below is driven by a hidden native input. Interact with any of them and watch the change log in section 03: every line there was fired by the native element.
Single, with <optgroup>, a disabled option and a search box:
multiple: click to toggle, full list as a tooltip:
Focus a widget, then ArrowUp/ArrowDown to move, Enter to pick.
Radio group on the horizontal axis (axisClass):
Checkboxes: the tick is supplied by config content, not an icon font:
type="date" with min/max and a preset value:
value: - | complete: -
type="datetime-local": day selection continues into time entry:
value: - | complete: -
Pick February of a leap year (2024): it has 29 days. Day cells carry their
weekday as a tooltip (daysToolTip).
Labels come from data-labels, size from data-dim:
File input: label, browse button, and the file name as a tooltip:
This trips people up, so the example uses both deliberately. select and
datePicker take the full attribute name; slideSwitch
and file take dataset names without the data- prefix.
The value is the attribute exactly as written in the markup.
select.config.sizeAttribute = "data-size"; // <select data-size="230px,40px">
The prefix is implied; give the key as it appears on element.dataset.
slideSwitch.config.dataAttributeNames = { size: "dim" }; // <input data-dim="70px,30px">
New markup is not converted automatically. refreshSelect(native) rebuilds one widget; refresh(container) converts whatever is new inside a container.
Both buttons in section 01 do exactly this.
One delegated change listener, bound to document and reading the
native element. Every line below proves a widget wrote its state through to the real
form control, which is what your submit will send.
The date picker is the exception: it writes the ISO value and the completeness flag onto the
native input's attributes without firing change, so the two state lines in
section 01 are driven by a MutationObserver instead.
Every builder validates its config, and autoBuild() refuses an incomplete setup.