Targeted validation
A form needs an explicit control to validate one field before submission.
Conform · Function
getButtonProps generates props for Conform intent buttons. These props let a submitted button request operations such as validating, resetting, updating, inserting, or removing form data.
getButtonProps creates the props for a Conform intent button. Called through an intent such as validate, reset, update, insert, or remove, it serializes the requested operation into the button so Conform can process it when the form is submitted.
form.<intent>.getButtonProps(options)| Name | Type | Description |
|---|---|---|
options | object | Options for the selected intent, such as name, index, value, or validated; the exact fields depend on the intent API. |
A props object for an intent button, including the serialized reserved name and intent value.
import { useForm } from '@conform-to/react';
export default function Example() {
const [form, fields] = useForm();
return (
<form id={form.id}>
<input name={fields.email.name} />
<button {...form.validate.getButtonProps({ name: fields.email.name })}>
Validate email
</button>
</form>
);
}This renders a button whose serialized intent targets the email field, so clicking it asks Conform to validate that field.
A form needs an explicit control to validate one field before submission.
A user should restore one field or the entire form to its initial state.
A form manages editable nested data or collections.
A collection editor needs declarative add or remove buttons.
It returns button props that encode a Conform submission intent. The button is then interpreted when the form submits, allowing an operation such as validation or resetting to target a field.
Follow-up: How would you target a nested or list field? Pass the corresponding field metadata name, such as fields.tasks.name, to the intent's getButtonProps call.
For validation, call form.validate.getButtonProps with an object containing the field metadata name. The resulting button marks that field for validation and exposes its resulting error through the normal form state.
Follow-up: How can the same pattern reset a field? Use form.reset.getButtonProps({ name: fields.tasks.name }) rather than the validate intent.
The options depend on the intent. Reset can receive name, update can receive name and value, and update can also receive validated: false to clear errors globally.
Follow-up: What distinction matters when updating a field? The name identifies the target, while value supplies the replacement field data; omitting name applies the operation more broadly.
useFormvalidateresetupdateinsertremove