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