-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A typed form array of typed from groups #24
Comments
Hi, @jmclagniez. Thanks for the feedback. It looks like you found a limitation of the library. Let me experiment a bit and get back to you. As I understand you'd expect to get a |
Hi, thanks for this library! Exactly, I would like to have a typedFormGroup and have access to my class attributes of type typedFromControl. The context is that my form is instantiated in an upper level |
I'm glad you liked it :) As I understand, you can not afford to create a Component for the top-level form and a Component for the invitee, which is what I would recommend. Yes? If so read on:So it turns out it is possible - I've created a branch - see these lines ImpracticalIt also turns out to be a royal pain, because
Looks like I'm not able (or Typescript is not) to make a recursive type pattern. :( ? Which means I need to do the types manually and it's a lot of work. It occurred to me that there is another way, which keeps the library simpler and sticks to a more tiered approach of handling nested forms. Workaround (kinda*)This is what I would suggest:
function createEmptyGroup() {
return typedFormGroup<PersonContact>({
name: typedFormControl(),
email: typedFormControl(),
});
}
const invitee1 = createEmptyGroup();
const invitee2 = createEmptyGroup();
const invitee3 = createEmptyGroup();
const formDN = typedFormGroup<PartyForm, TypedArraysIn<PartyForm, 'invitees', 'invitees'>>({
event: typedFormControl(eventDefault()),
invitees: typedFormArray<PersonContact[], PersonContact, 'group'>([invitee1, invitee2]),
});
formDN.push(invitee3) OR function createEmptyGroup() {
return typedFormGroup<PersonContact>({
name: typedFormControl(),
email: typedFormControl(),
});
}
const invitees: TypedFormGroup<PersonContact>[] = [];
invitees.push(createEmptyGroup());
invitees.push(createEmptyGroup());
const formDN = typedFormGroup<PartyForm, TypedArraysIn<PartyForm, 'invitees', 'invitees'>>({
event: typedFormControl(eventDefault()),
invitees: typedFormArray<PersonContact[], PersonContact, 'group'>(invitees),
});
formDN.push(createEmptyGroup()) *kinda not a workaround, rather segregating the tiers of your form cake |
I'm trying to create a typed form array of typed form groups. I have not found any related example. Is it possible to do so ?
My test :
The text was updated successfully, but these errors were encountered: