AsterUIDocsv1.0.2

Docs / Guides

Submit a form and show the result

Project settings example

AsterUI's Form renders a native form and prevents the default navigation before invoking onSubmit. Enter a project name in the example and submit with Enter. Try submitting an empty value to see the browser enforce the required field.

Install the source for this recipe with the following command.

sh
npx @fierst/ui@1.0.2 add form input switch button

Read the submitted values

Give each submitted input a name. Read new FormData(event.currentTarget) inside the synchronous submit handler, while the event still identifies its form. The example’s save handler reads the switch preference from its signal because the displayed switch is managed separately from the named input. It updates an output element so the result stays visible next to the field.

Add server persistence

Read the values first, then start your request. Keep the draft visible until the server confirms it was saved. A submit button can take the Button component’s loading or disabled prop while a request is in flight. Display a field-specific validation message through the Input error prop and reserve a toast for supplementary confirmation.

Choose who owns the draft

Use defaultValue when the control can manage its initial state. Pass value and the corresponding change callback when another component must read or replace that value. For a one-field rename, InlineEdit also supports Enter to commit and Escape to discard. Try InlineEdit.