copyFrom()
function copyFrom<TForm, TSource, TTarget>(
source,
target,
options?): void;
Defined in: core/behavior/behaviors/copy-from.ts:67
Копирует значения из одного поля/группы в другое при выполнении условия
Type Parameters
TForm
TForm
TSource
TSource
TTarget
TTarget
Parameters
source
FieldPathNode<TForm, TSource>
Откуда копировать
target
FieldPathNode<TForm, TTarget>
Куда копировать
options?
CopyFromOptions<TSource, TForm>
Опции копирования (when, fields, transform, debounce)
Returns
void
Examples
import { copyFrom, type BehaviorSchemaFn } from '@reformer/core/behaviors';
interface ContactForm {
sameEmail: boolean;
email: string;
emailAdditional: string;
}
export const contactBehavior: BehaviorSchemaFn<ContactForm> = (path) => {
copyFrom(path.email, path.emailAdditional, {
when: (form) => form.sameEmail === true,
});
};
import { copyFrom, type BehaviorSchemaFn } from '@reformer/core/behaviors';
interface Address { country: string; region: string; city: string; street: string }
interface ProfileForm {
sameAsRegistration: boolean;
registrationAddress: Address;
residenceAddress: Address;
}
export const profileBehavior: BehaviorSchemaFn<ProfileForm> = (path) => {
copyFrom(path.registrationAddress, path.residenceAddress, {
when: (form) => form.sameAsRegistration === true,
fields: ['country', 'region', 'city'], // street НЕ копируем
transform: (addr) => ({
...addr,
country: addr.country.toUpperCase(), // нормализация при копировании
}),
debounce: 200,
});
};