Components
← All components

Nested Form

stimeo--nested-form

Adds/removes fields_for rows from a template — the Headless cocoon.

  • Rails / Turbo

The stimeo--nested-form controller is the Headless successor to the cocoon / nested_form gems for Rails fields_for + accepts_nested_attributes_for. Adding a row clones a <template>, replaces its __INDEX__ placeholder with a unique index, and appends it; removing a row drops an unsaved one from the DOM or, for a persisted row carrying a _destroy flag, sets the flag to 1 and hides it so Rails destroys it on submit. Row state lives only in the DOM (no module-scope counter), so connect recomputes idempotently after a Turbo swap, and remove buttons are handled by delegation so cloned rows work without per-row wiring. Adding moves focus to the new row's first control and removing returns focus to a neighbor (WCAG 2.2 2.4.3); count changes are announced through the shared stimeo--announcer when announce + countMessage are set (WCAG 2.2 4.1.3). It enforces min/max and dispatches stimeo--nested-form:add / :remove. Behavior only — the server-side nested attributes and all styling stay with the consumer.

running