DialogForm
Runs a form inside a dialog: it blocks closing while a request is pending, shows errors, and closes on success.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add DialogForm- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View DialogForm code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import {
Button,
Dialog,
DialogBody,
DialogClose,
DialogFooter,
DialogForm,
DialogHeader,
DialogTitle,
ErrorSummary,
Field,
FieldError,
Input,
Label
} from '@santi020k/lumen-astro'
---
<Button data-ui-dialog-trigger="ex-dialog-form">Rename project</Button>
<Dialog id="ex-dialog-form" aria-labelledby="ex-dialog-form-title">
<DialogForm id="ex-dialog-form-rename" failureMessage="The project was not renamed. Try again.">
<DialogHeader>
<DialogTitle id="ex-dialog-form-title">Rename project</DialogTitle>
<p>The new name shows everywhere the project is listed.</p>
</DialogHeader>
<DialogBody>
<ErrorSummary heading="Check these fields" id="ex-dialog-form-errors" />
<Field>
<Label for="ex-dialog-form-name">Project name</Label>
<Input data-error-required="Enter a project name." id="ex-dialog-form-name" name="name" required />
<p data-ui-field-hint id="ex-dialog-form-name-hint">Type “taken” to see a server error.</p>
<FieldError id="ex-dialog-form-name-error" />
</Field>
</DialogBody>
<DialogFooter>
<DialogClose variant="outline">Cancel</DialogClose>
<Button type="submit">Rename</Button>
</DialogFooter>
</DialogForm>
</Dialog>
<script>
import {
type LumenFormErrorInput,
lumenDialogFormSubmitEventName,
readLumenDialogFormSubmitDetail
} from '@santi020k/lumen-core'
// Illustrative only: a real app sends the values to its server.
const renameProject = (name: string) => new Promise<LumenFormErrorInput>(resolve => {
setTimeout(() => {
resolve(name.trim().toLowerCase() === 'taken' ?
[{ controlId: 'ex-dialog-form-name', message: 'That name is taken.', name: 'name' }] :
undefined)
}, 800)
})
document.addEventListener(lumenDialogFormSubmitEventName, event => {
const detail = readLumenDialogFormSubmitDetail(event)
if (detail?.form.id !== 'ex-dialog-form-rename') return
const name = detail.values.get('name')
// Call waitUntil before the listener returns, so the dialog stays open while the request runs.
detail.waitUntil(renameProject(typeof name === 'string' ? name : ''))
})
</script>'use client'
import { useState } from 'react'
import {
Button,
Dialog,
DialogBody,
DialogClose,
DialogFooter,
DialogForm,
DialogHeader,
DialogTitle,
ErrorSummary,
Field,
FieldError,
Input,
Label
} from '@santi020k/lumen-react'
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
// Illustrative only: a real app sends the values to its server.
async function renameProject(values: FormData) {
await wait(800)
return values.get('name') === 'taken'
? [{ controlId: 'project-name', message: 'That name is taken.', name: 'name' }]
: undefined
}
export function Example() {
const [open, setOpen] = useState(false)
return (
<>
<Button onClick={() => setOpen(true)}>Rename project</Button>
<Dialog open={open} onOpenChange={setOpen} aria-labelledby="rename-title">
<DialogForm failureMessage="The project was not renamed. Try again." submit={renameProject}>
{({ errors, pending }) => {
const error = errors.fields.find(item => item.name === 'name')?.message
return (
<>
<DialogHeader><DialogTitle id="rename-title">Rename project</DialogTitle></DialogHeader>
<DialogBody>
<ErrorSummary errors={errors} heading="Check these fields" id="rename-errors" />
<Field invalid={Boolean(error)}>
<Label htmlFor="project-name">Project name</Label>
<Input
aria-describedby="project-name-error"
aria-invalid={Boolean(error)}
id="project-name"
name="name"
required
/>
<FieldError id="project-name-error" message={error} />
</Field>
</DialogBody>
<DialogFooter>
<DialogClose variant="outline">Cancel</DialogClose>
<Button type="submit" loading={pending}>Rename</Button>
</DialogFooter>
</>
)
}}
</DialogForm>
</Dialog>
</>
)
}<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements([
'Button', 'Dialog', 'DialogBody', 'DialogClose', 'DialogFooter', 'DialogForm', 'DialogHeader', 'DialogTitle',
'ErrorSummary', 'Field', 'FieldError', 'Input', 'Label'
])
</script>
<lumen-button data-ui-dialog-trigger="rename-dialog">Rename project</lumen-button>
<lumen-dialog id="rename-dialog">
<dialog aria-labelledby="rename-title">
<lumen-dialog-form failure-message="The project was not renamed. Try again.">
<form data-ui-form id="rename-form" method="dialog">
<lumen-dialog-header><lumen-dialog-title><h2 id="rename-title">Rename project</h2></lumen-dialog-title></lumen-dialog-header>
<lumen-dialog-body>
<lumen-error-summary hidden aria-labelledby="rename-errors-heading"><h2 id="rename-errors-heading">Check these fields</h2><ul></ul></lumen-error-summary>
<lumen-field>
<lumen-label id="project-name-label">Project name</lumen-label>
<lumen-input aria-labelledby="project-name-label" data-error-required="Enter a project name." id="project-name" name="name" required></lumen-input>
<lumen-field-error hidden></lumen-field-error>
</lumen-field>
</lumen-dialog-body>
<lumen-dialog-footer>
<lumen-dialog-close><button type="button">Cancel</button></lumen-dialog-close>
<lumen-button type="submit">Rename</lumen-button>
</lumen-dialog-footer>
</form>
</lumen-dialog-form>
</dialog>
</lumen-dialog>
<script type="module">
// Illustrative only: send the values to your server.
document.getElementById('rename-form')?.addEventListener('ui:dialog-form-submit', event => {
const name = event.detail.values.get('name')
// Call waitUntil before the listener returns, so the dialog stays open while the request runs.
event.detail.waitUntil(new Promise(resolve => {
setTimeout(() => resolve(name === 'taken'
? [{ controlId: 'project-name', message: 'That name is taken.', name: 'name' }]
: undefined), 800)
}))
})
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let dialog = use_dialog();
let mut name = use_signal(|| "Lumen".to_string());
rsx! {
DialogTrigger { dialog, "Rename project" }
Dialog { dialog, aria_labelledby: "rename-title",
DialogForm {
submit: move |values: DialogFormValues| -> DialogFormFuture {
let next = values.get("name").unwrap_or_default().trim().to_string();
Box::pin(async move {
if next.is_empty() {
return Ok(FormErrors::from(vec![
FormFieldError::new("name", "Enter a project name.")
.control_id("project-name"),
]));
}
// Send `next` to your API here; `?` turns its error into a failure.
Ok(FormErrors::default())
})
},
render: move |state: DialogFormState| {
let message = state.errors.field("name").first().map(|error| error.message.clone());
rsx! {
DialogHeader { DialogTitle { id: "rename-title", "Rename project" } }
DialogBody {
ErrorSummary { errors: state.errors.clone(), id: "rename-errors" }
Field { control_id: "project-name", invalid: message.is_some(),
Label { r#for: "project-name", "Name" }
Input {
id: "project-name",
name: "name",
value: name(),
oninput: move |event: FormEvent| name.set(event.value()),
}
FieldError { message }
}
}
DialogFooter {
DialogClose { variant: ButtonVariant::Secondary, "Cancel" }
Button { r#type: "submit", loading: state.pending, "Save" }
}
}
},
}
}
}
}Framework differences
React: Pass submit instead of listening for ui:dialog-form-submit. The pending state locks the Dialog without dismissOn props. Render ErrorSummary with errors and pass loading={pending} to the submit Button.
Elements: Put a native <form data-ui-form> inside lumen-dialog-form, inside the native dialog. Close controls and submit buttons update on their own while a submission is pending.
Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add DialogFormpnpm add @santi020k/lumen-reactlumen add DialogForm --target reactpnpm add @santi020k/lumen-elementslumen add DialogForm --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| children | DialogHeader, DialogBody, DialogFooter, or task content | required | Renders the native form of the enclosing Dialog or AlertDialog. With a DialogBody inside, the header and footer stay visible while the body scrolls. |
| method | "dialog" | "post" | "get" | "dialog" | Used when the form submits natively, such as before JavaScript loads: "dialog" closes the dialog and "post" sends the form. |
| failureMessage | string | "Something went wrong. Try again." | Shown in the ErrorSummary when a submission fails. Every value stays. Elements uses failure-message. |
| submit | (values: FormData) => PromiseLike<LumenFormErrorInput> | - | Runs after client validation passes. Resolve with field or form errors to keep the dialog open, or undefined to close it. Without submit, a valid form submits natively. |
| onSuccess | () => void | - | Called when a submission resolves without errors. |
| children({ errors, pending }) | (state: { errors: LumenFormErrors; pending: boolean }) => ReactNode | - | Pass errors to ErrorSummary and pending to the submit Button loading prop. DialogClose disables itself while pending. |
| ui:dialog-form-submit | CustomEvent<LumenDialogFormSubmitDetail> | - | Fires after client validation passes. Call event.detail.waitUntil(promise) synchronously to run the pending flow. |
| form[data-ui-form] | native child | required | lumen-dialog-form adds the form classes, data-slot, and data-ui-dialog-form to this form and runs its behavior. |
| UIPrimitives | Astro runtime | required | Adds validation, the pending lock, and error focus. Without it, the form submits natively. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize DialogForm
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-dialog-form {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-dialog-form through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| form[data-ui-form] | native child | required | lumen-dialog-form adds the form classes, data-slot, and data-ui-dialog-form to this form and runs its behavior. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Enter in a text field | Submit the form. If a field is invalid, the dialog stays open and focus moves to the first error. |
| Escape | Close the dialog as usual and clear the errors. While a submission is pending, Escape does nothing. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:dialog-form-submit | DialogForm form ([data-ui-dialog-form]) | LumenDialogFormSubmitDetail: { form: HTMLFormElement, submitter: HTMLElement | null, values: FormData, waitUntil(promise: PromiseLike<LumenFormErrorInput>): void } | Cancelable. Bubbles after a valid submit. Call waitUntil synchronously: the promise resolves to field or form errors, or undefined to close the dialog, and a rejection shows failureMessage. Without waitUntil the form submits natively; preventDefault cancels that. React uses submit instead. |