Forms

Form

Thin form root that owns asynchronous submit state and prevents duplicate submissions while preserving native form behavior.

import { Form } from '@lostgradient/cinder';
formsubmit
01

Overview

Reference usage

Form is a thin native form root that exposes asynchronous submission state to its child snippet and ignores duplicate submissions while the current handler is pending.

Use native validation and form controls as usual. The component owns only submit coordination; it does not replace native serialization, validation, or reset behavior.

Usage

svelte
<script lang="ts">
  import { Form } from '@lostgradient/cinder';
  import { Input } from '@lostgradient/cinder';
  import { Button } from '@lostgradient/cinder';
</script>

<Form onSubmit={() => undefined}>
  {#snippet children({ submitting })}
    <Input id="form-name" name="name" label="Name" value="" disabled={submitting} />
    <Button type="submit" disabled={submitting}>Save</Button>
  {/snippet}
</Form>

onSubmit may return a promise. While it is pending, the child snippet receives { submitting: true }; duplicate submits are ignored until the handler settles. Native form serialization, constraint validation, reset behavior, and the submit event remain the browser's responsibility. If the handler rejects, catch it in the host and keep the controls mounted so the user can correct and resubmit.

Problems at the fields

Validation never disables the submit button. Pressing it runs onSubmit, and once the handler settles Form moves focus to the first control that reports a problem (aria-invalid="true", or data-cinder-invalid="true" on a custom control), skipping disabled ones, so the person lands on the first message, which sits under its field. Set focusProblemOnSubmit={false} when the page manages focus itself. focusFirstProblem(form) is exported for a page that needs the same move outside a submit.

readingColumn holds the form to a single column up to 720px (--cinder-form-reading-column-width changes the width), as a New goal page reads. For the bar at the end of the form, with the unsaved-change count and the failed-save message, see FormActions.

Live preview

Basic form

02

When to use

Use when
  • A form needs a shared pending state while an asynchronous submit handler runs.
Avoid when
  • Submission is entirely native and no pending UI needs to be coordinated.
03

Examples

Basic form

Native form submission with Cinder controls.

Save stays enabled; focus goes to the first problem

Validation never disables Save. Pressing it puts each message at its field, under it with a warning glyph, and moves focus to the first problem. readingColumn holds the form to one column up to 720px.

04

Props

Props for form
Name
Type
Default
Description
onSubmit (event: SubmitEvent) => voidPromise<void> May return a promise; while pending, the child snippet receives { submitting: true } and duplicate submits are ignored until it settles.
children snippet Form controls. Receives { submitting } so descendants can disable themselves while onSubmit is pending.
readingColumn boolean false Holds the form to a single reading column, up to 720px (45rem).
focusProblemOnSubmit boolean true After onSubmit settles, moves focus to the first field that reports a problem.