Skip to main content

disableWhen()

function disableWhen<TForm>(
field,
condition,
options?): void;

Defined in: core/behavior/behaviors/enable-when.ts:167

Условное выключение поля (инверсия enableWhen)

Type Parameters

TForm

TForm

Parameters

field

FieldPathNode<TForm, any>

Поле для выключения

condition

(form) => boolean

Функция условия (true = disable, false = enable)

options?

EnableWhenOptions

Опции (resetOnDisable, debounce)

Returns

void

Examples

import { disableWhen, type BehaviorSchemaFn } from '@reformer/core/behaviors';

interface ConfirmForm {
isConfirmed: boolean;
editableField: string;
}

export const confirmBehavior: BehaviorSchemaFn<ConfirmForm> = (path) => {
// Поле блокируется после установки чекбокса подтверждения
disableWhen(path.editableField, (form) => form.isConfirmed === true);
// resetOnDisable НЕ ставим — сохраняем введённый текст
};
import { disableWhen, type BehaviorSchemaFn } from '@reformer/core/behaviors';

interface PromoForm {
loanType: 'mortgage' | 'consumer';
promoCode: string;
}

export const promoBehavior: BehaviorSchemaFn<PromoForm> = (path) => {
// Промокод недоступен для потребительских кредитов и сбрасывается
disableWhen(path.promoCode, (form) => form.loanType === 'consumer', {
resetOnDisable: true,
});
};