Skip to main content

applyEach()

function applyEach<U>(array, schema): void;

Defined in: packages/reformer/src/form/validation/operators.ts:208

Применить схему к КАЖДОМУ элементу массива под-форм. Схема элемента — обычная ValidationDefinition над типом элемента: тот же набор правил подключается и к группе через apply.

У каждого элемента своя область: cross внутри схемы получает снапшот элемента.

Type Parameters​

U​

U extends object

Parameters​

array​

ArrayBinding<U> | ModelArray<U>

schema​

ValidationDefinition<U>

Returns​

void

Example​

const propertyRules = defineValidation<Property>(({ model, cross }) => {
validate(model.$.type, [required()]);
cross(model.$.estimatedValue, (property) =>
property.hasEncumbrance && property.estimatedValue < 100_000 ? tooCheap : null
);
});

applyEach(model.$.properties, propertyRules);