Applies a schema to each item of an array.
API
function applyEach<TValue>(
path: { [ɵɵTYPE]: [TValue[], Root] },
schema: NoInfer<SchemaOrSchemaFn<TValue, Item>>,
): void;
applyEach
void
Applies a schema to each item of an array.
@parampath
{ [ɵɵTYPE]: [TValue[], Root]; }
The target path for an array field whose items the schema will be applied to.
@paramschema
NoInfer<SchemaOrSchemaFn<TValue, Item>>
A schema for an element of the array, or function that binds logic to an element of the array.
@returns
void
Usage Notes
const nameSchema = schema<{first: string, last: string}>((name) => { required(name.first); required(name.last);});const namesForm = form(signal([{first: '', last: ''}]), (names) => { applyEach(names, nameSchema);});
When binding logic to the array items, the FieldTree
for the array item is passed as an
additional argument. This can be used to reference other properties on the item.
const namesForm = form(signal([{first: '', last: ''}]), (names) => { applyEach(names, (name) => { error( name.last, (value, nameField) => value === nameField.first().value(), 'Last name must be different than first name', ); });});
Jump to details