Dynamic form rows
Add a blank row to a repeatable form section.
Conform · Module
The insert intent adds a new item to an array field without submitting the form. It can append or place the item at an index, initialize it directly, or populate it from another validated field.
The insert intent adds an item to an array field without submitting the form. Provide the array field name, optionally choose its index, and supply a default value; if the index is omitted, the item is appended.
insert(options): void| Name | Type | Description |
|---|---|---|
name | string | Name of the array field receiving the item. |
index | number | Optional position at which to insert the item; omission appends it. |
defaultValue | unknown | Optional initial value for the new item. |
from | string | Optional source field whose value is validated and inserted. |
onInvalid | 'revert' | Optional invalid-operation behavior; currently supports 'revert'. |
void
const intent = useIntent(form.ref);
intent.insert({
name: fields.tasks.name,
index: 1,
defaultValue: { title: '' },
});This inserts a new item into the tasks array at index 1 with an initial value.
Add a blank row to a repeatable form section.
Turn an input value into a newly added tag.
Place a new record at a user-selected position.
Call the dispatcher’s insert method with the array field’s name. The index is optional; without it, the new item is appended.
Follow-up: How can an item be populated from another field? Use from; Conform validates that source value, inserts it only when valid, and clears the source field afterward.
Pass defaultValue in the insert options. This provides the initial value for the new array item.
Follow-up: What happens when the source value supplied through from fails validation? The operation is cancelled and the error is displayed on the source field.
Set onInvalid to 'revert' when an array-level validation error should cancel the operation, such as when the array exceeds its maximum length. This option requires synchronous error availability.
Follow-up: Why might an insert be cancelled even when the item itself is valid? Array-level validation can reject the updated list, and the revert behavior cancels the insertion.
useIntentuseFormform.insertIntent buttonNested object and Array