Form
Wraps ARC UI inputs in a form that validates them on submit and fires arc-submit with their values.
<arc-form>Overview
Form wraps ARC UI inputs in a real <form>. On submit it checks every field, puts each failing field's message on that field, and fires arc-invalid with the list of errors. When everything passes it fires arc-submit with { values, formData, valid }. Use it whenever you collect more than one field, so required, patterns and an error summary work without validation code of your own.
Validation comes from the controls. Form doesn't decide whether a field is filled. It calls each control's checkValidity() and reads its validationMessage. A control that knows its own empty state, such as a multi-select with an empty array or a date range with one end set, is judged on its own terms. Only form-associated elements whose tag starts with arc- take part, so a control you wrote yourself under another tag name isn't validated, serialized or disabled with the form. Form only clears error text it wrote, so an error you set from a server response survives the next submit.
Fields can be anywhere inside the form. A control inside a Fieldset, a Card or any layout component is still found, validated, serialized and disabled with the form.
submit() is for a submit control outside the form. A button outside <arc-form> doesn't submit it: a wizard's Next button in a parent toolbar, a Save button in the app header, a keyboard shortcut. submit() goes through the real <form>, so validation runs and arc-submit fires as if a submit button inside had been pressed.
action submits natively. With action (and method) set, a valid submit fires arc-submit and then lets the browser submit the form and navigate. The request carries the same entries as arc-submit's formData, including fields nested in a Fieldset or a layout component.
reset() restores starting values. Each control goes back to the state it had when it first connected, as reset does in HTML. arc-reset fires after.
Input, Textarea, Select, Checkbox, Toggle and RadioGroup are form-associated through ElementInternals, so they also submit with a plain <form action="/api/contact" method="POST"> once the components are loaded.
Guidelines
Do
- Put all related fields in one Form, so they validate and submit together
- Give every field a unique `name`. Without one, its key falls back to its label
- Set `required` on mandatory fields and let Form show the messages
- End the form with a Button that has `type="submit"`
- Set `loading` while an async submit runs, to prevent duplicate requests
- Listen for `arc-submit`, not the native `submit`, to get the validated values
- Give every field a label, so the error summary reads well
Don't
- Don't put one Form inside another. HTML doesn't allow nested forms
- Don't write validation by hand for rules the constraint API already covers
- Don't rely on client-side validation alone. Validate on the server too
- Don't expect a button outside the Form to submit it. Call `submit()` from that button
- Don't use `novalidate` to get around broken validation. Fix the constraints
Features
- An error summary at the top of the form, above the fields, lists what failed. Set `no-error-summary` to show errors your own way
- With `novalidate`, failing fields still get their error messages, but the submit goes ahead and `arc-submit` reports `valid: false`
- `disabled` disables every field in the form
- `loading` dims the form to 70% opacity, blocks pointer input and ignores submits until it's cleared. Each `arc-button` with `type="submit"` inside it shows its spinner and is disabled meanwhile
- Enter in a single-line input submits the form
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-form>
<div style="display:flex; flex-direction:column; gap:16px; width:100%; max-width:480px;">
<arc-input label="Name" name="name" placeholder="Jane Doe" required></arc-input>
<arc-input label="Email" name="email" type="email" placeholder="jane@example.com" required></arc-input>
<arc-textarea label="Message" name="message" rows="4" placeholder="How can we help?" required></arc-textarea>
<arc-button variant="primary" type="submit">Send message</arc-button>
</div>
</arc-form>
<script>
document.querySelector('arc-form')
.addEventListener('arc-submit', (e) => {
console.log('Form data:', Object.fromEntries(e.detail.formData));
});
</script>import { Button, Form, Input, Textarea } from '@arclux/arc-ui-react';
function ContactForm() {
const handleSubmit = (e: CustomEvent) => {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
};
return (
<Form onArcSubmit={handleSubmit}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, width: '100%', maxWidth: 480 }}>
<Input label="Name" name="name" placeholder="Jane Doe" required />
<Input label="Email" name="email" type="email" placeholder="jane@example.com" required />
<Textarea label="Message" name="message" rows={4} placeholder="How can we help?" required />
<Button variant="primary" type="submit">Send message</Button>
</div>
</Form>
);
}<script setup>
import { Button, Form, Input, Textarea } from '@arclux/arc-ui-vue';
function handleSubmit(e) {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
}
</script>
<template>
<Form @arc-submit="handleSubmit">
<div style="display:flex; flex-direction:column; gap:16px; width:100%; max-width:480px;">
<Input label="Name" name="name" placeholder="Jane Doe" required />
<Input label="Email" name="email" type="email" placeholder="jane@example.com" required />
<Textarea label="Message" name="message" rows="4" placeholder="How can we help?" required />
<Button variant="primary" type="submit">Send message</Button>
</div>
</Form>
</template><script>
import { Button, Form, Input, Textarea } from '@arclux/arc-ui-svelte';
function handleSubmit(e) {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
}
</script>
<Form on:arc-submit={handleSubmit}>
<div style="display:flex; flex-direction:column; gap:16px; width:100%; max-width:480px;">
<Input label="Name" name="name" placeholder="Jane Doe" required />
<Input label="Email" name="email" type="email" placeholder="jane@example.com" required />
<Textarea label="Message" name="message" rows="4" placeholder="How can we help?" required />
<Button variant="primary" type="submit">Send message</Button>
</div>
</Form>import { Component } from '@angular/core';
import { Button, Form, Input, Textarea } from '@arclux/arc-ui-angular';
@Component({
imports: [Button, Form, Input, Textarea],
template: `
<arc-form (arc-submit)="handleSubmit($event)">
<div style="display:flex; flex-direction:column; gap:16px; width:100%; max-width:480px;">
<arc-input label="Name" name="name" placeholder="Jane Doe" required></arc-input>
<arc-input label="Email" name="email" type="email" placeholder="jane@example.com" required></arc-input>
<arc-textarea label="Message" name="message" rows="4" placeholder="How can we help?" required></arc-textarea>
<arc-button variant="primary" type="submit">Send message</arc-button>
</div>
</arc-form>
`,
})
export class ContactFormComponent {
handleSubmit(e: CustomEvent) {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
}
}import { Button, Form, Input, Textarea } from '@arclux/arc-ui-solid';
function ContactForm() {
const handleSubmit = (e: CustomEvent) => {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
};
return (
<Form onArcSubmit={handleSubmit}>
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '16px', width: '100%', 'max-width': '480px' }}>
<Input label="Name" name="name" placeholder="Jane Doe" required />
<Input label="Email" name="email" type="email" placeholder="jane@example.com" required />
<Textarea label="Message" name="message" rows={4} placeholder="How can we help?" required />
<Button variant="primary" type="submit">Send message</Button>
</div>
</Form>
);
}import { Button, Form, Input, Textarea } from '@arclux/arc-ui-preact';
function ContactForm() {
const handleSubmit = (e: CustomEvent) => {
const data = Object.fromEntries(e.detail.formData);
console.log('Form data:', data);
};
return (
<Form onArcSubmit={handleSubmit}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 16, width: '100%', maxWidth: 480 }}>
<Input label="Name" name="name" placeholder="Jane Doe" required />
<Input label="Email" name="email" type="email" placeholder="jane@example.com" required />
<Textarea label="Message" name="message" rows={4} placeholder="How can we help?" required />
<Button variant="primary" type="submit">Send message</Button>
</div>
</Form>
);
}API
actionstring''- Form action URL for native form submission. When set, a valid submit navigates to this URL with the browser's own form submission, carrying the same entries as
arc-submit'sformData. methodstring''- HTTP method for native form submission (GET or POST). Only applies when action is set.
disabledbooleanfalse- Disables the entire form, propagating the disabled state to every child field. Useful for read-only previews or while awaiting permissions.
novalidatebooleanfalse- When true, skips built-in constraint validation on submit. Use this when you need to implement a fully custom validation flow while still using Form for data serialisation.
loadingbooleanfalse- Marks an asynchronous submission in progress. Submits are ignored, the form dims and stops taking pointer input, and every
arc-buttonwithtype="submit"inside it shows its spinner and is disabled. Clearing it releases only the buttons it set. errorSummarybooleantrue- When true, renders an aggregated list of validation errors above the submit area after a failed submission attempt. Set to false to handle error display manually.
Methods
submit()- Submit the form as though its submit button had been pressed: validation
runs, and
arc-submitfires cancelably. The path for a submit control the form cannot own: a wizard's "Next" in a parent toolbar, a keyboard shortcut, since a button outside the form does not trigger it. Routed through the real<form>so action-mode submits still navigate. reset()- Reset every child control to the state it had when it first connected,
and clear error display.
Delegates to each control's formResetCallback: the same path a native
form.reset() takes, which never reaches these controls because they live
in this element's light DOM rather than inside the shadow <form>. The form
used to blank them instead (
value = '',checked = false), which is not what reset means: a control that shipped with a default lost it, and a non-string value (a multi-select's array, a date range's object) was left untouched entirely.
Events
arc-invalid- Fired when validation fails, with error details
arc-submit- Fired on valid form submission with serialized form data
arc-reset- Fired when the form is reset via the .reset() method
See also
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.
- SelectA dropdown for choosing one option from a list in a form.
- CheckboxA checkbox with a built-in label and an indeterminate state for "select all" boxes.
- ToggleAn on/off switch for a setting that takes effect at once.
- TextareaA multi-line text field with a label, an optional character counter and an error message.
- ButtonAction button with three variants for action hierarchy and prefix and suffix slots for icons. For links, slot a real anchor, which works before JavaScript loads.