--- description: 'How to build forms with ranui: r-input, r-checkbox, and r-select work directly inside a plain native
, no wrapper component required.' --- # Forms ranui does not ship a ``-wrapping component. `r-input`, `r-checkbox`, and `r-select` are themselves [Form-Associated Custom Elements](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_form-associated_custom_elements) (each calls `attachInternals()` and relays its value via `ElementInternals.setFormValue()`), so they already work inside a plain native ``: `new FormData(form)` collects them, `form.reset()` restores their pre-interaction state, and a `required` field blocks submission and shows the browser's native validation UI, anchored on the field. None of that needs any ranui-specific markup. > **Use when** you're assembling a form out of `r-input`/`r-checkbox`/`r-select`: just use a real ``, and reach for `serializeForm()` (below) if you want the submitted values as a plain object instead of hand-rolling `FormData` iteration. ## Quick Start All three field types, submitted with a plain ``. Try changing a field and submitting to see the live result below. This demo builds the object with the browser's own `FormData`/`Object.fromEntries` (no import needed); `serializeForm()`, introduced next, does the same thing plus one thing `Object.fromEntries` can't: a repeated field name comes back as an array instead of silently keeping only the last value. Member Admin Subscribe to newsletter
> As the [Layout](#layout) section below covers: fields have no default form-level layout of > their own, so every example on this page (including this one) sets its own `
` CSS > (`display: flex; flex-direction: column; gap: …`). Omitting it stacks fields in plain > in-flow order with no spacing between them, which reads as broken/overlapping rather than > a form. ```html Member Admin Subscribe to newsletter
``` ## `serializeForm(form)` Collects a `
`'s named fields into a plain object via `FormData`: the boilerplate every consumer otherwise hand-rolls to turn a submit into something they can `JSON.stringify` or send as a fetch body. It's a plain function with no dependency on ranui fields specifically; it works with any real ``. ```ts function serializeForm(form: HTMLFormElement): Record; ``` A field with more than one value under the same `name` (e.g. multiple checkboxes sharing a name) comes back as an array; everything else comes back as a single value. ```ts import { serializeForm } from 'ranui'; const data = serializeForm(document.querySelector('form')); // { username: 'alice', tags: ['a', 'b'] } fetch('/api/signup', { method: 'POST', body: JSON.stringify(data) }); ``` ## Layout {#layout} Fields have no default form-level layout: style your own `` with plain CSS: ```html
``` ## Validation and reset `r-input`, `r-checkbox`, and `r-select` all support `required` (which blocks submission and triggers the browser's native validation bubble, exactly like a native field) plus `checkValidity()`, `reportValidity()`, `validity`, and `validationMessage`. A native `form.reset()` (or ` ```html
``` ## Why no `` wrapper? A plain native `
` is already enough: ranui's field components work inside one directly, with no wrapper needed. `serializeForm()` fills the one real gap: turning a submission into a plain object.