Skip to main content

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,
});
};

See​

docs/llms/23-copy-from.md