Перейти к основному содержимому

syncFields()

function syncFields<TForm, T>(
field1,
field2,
options?): void;

Defined in: core/behavior/behaviors/sync-fields.ts:60

Двусторонняя синхронизация двух полей

Type Parameters

TForm

TForm extends FormFields

T

T extends FormValue

Parameters

field1

FieldPathNode<TForm, T>

Первое поле

field2

FieldPathNode<TForm, T>

Второе поле

options?

SyncFieldsOptions<T>

Опции (transform асимметричен — применяется только field1 → field2; debounce)

Returns

void

Examples

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

interface MirrorForm {
syncField1: string;
syncField2: string;
}

export const mirrorBehavior: BehaviorSchemaFn<MirrorForm> = (path) => {
syncFields(path.syncField1, path.syncField2);
};
import { syncFields, type BehaviorSchemaFn } from '@reformer/core/behaviors';

interface CodeForm {
internalCode: string; // канонический формат
displayCode: string; // показываем пользователю
}

export const codeBehavior: BehaviorSchemaFn<CodeForm> = (path) => {
// internalCode → displayCode: применяется toUpperCase
// displayCode → internalCode: пишется как есть
syncFields(path.internalCode, path.displayCode, {
transform: (value) => (typeof value === 'string' ? value.toUpperCase() : value),
debounce: 150, // сглаживает дёргание каретки
});
};

See

docs/llms/24-sync-fields.md