vUX / FormComponents / v4.1.0

Native inputs, better dressed.

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.

fc.select().autoBuild(); // every .demo-select on the page

01All six builders

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.

select

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 & checkbox

Radio group on the horizontal axis (axisClass):

Checkboxes: the tick is supplied by config content, not an icon font:

datePicker

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).

slideSwitch & file

Labels come from data-labels, size from data-dim:

File input: label, browse button, and the file name as a tooltip:

02Two attribute conventions

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.

1

Full attribute name

The value is the attribute exactly as written in the markup.

select.config.sizeAttribute = "data-size";
// <select data-size="230px,40px">
2

Dataset name

The prefix is implied; give the key as it appears on element.dataset.

slideSwitch.config.dataAttributeNames = { size: "dim" };
// <input data-dim="70px,30px">
↻

Content added later

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.

03The native input stays the source of truth

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.

native change log

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.

04Bad input fails immediately

Every builder validates its config, and autoBuild() refuses an incomplete setup.

No error yet: press one of the buttons above.