Skip to content
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

How to declare a form NgxSubFormRemapComponen? #274

Open
rlzdesenv opened this issue Sep 2, 2022 · 2 comments
Open

How to declare a form NgxSubFormRemapComponen? #274

rlzdesenv opened this issue Sep 2, 2022 · 2 comments

Comments

@rlzdesenv
Copy link

before I declared the component and extended NgxSubFormRemapComponent

export class ContribuinteFormComponent extends NgxSubFormRemapComponent<Pessoa, PessoaForm>

could you please an example of how to declare in the new way

    public form: NgxSubFormRemapComponent<Pessoa, PessoaForm>;

    constructor() {
        this.form = createForm<PessoaForm>(this, {
            formType: FormType.SUB,
            formControls: {
                tipo: new FormControl(null, Validators.required),
                fisica: new FormControl(null),
                juridica: new FormControl(null),
            },
        })
    }
@svenank3r
Copy link

svenank3r commented Oct 10, 2022

Dont know if this is still relevant for you but:

If you remap in a subForm, you need to supply the object and the form in the generic of the createForm function (just like you would have in the extends).
When remapping the toFormGroup and fromFormGroup also need to be supplied in the createForm function.

    form = createForm<Pessoa, PessoaForm>(this, {
        formType: FormType.SUB,
        formControls: {
            tipo: new FormControl(null, Validators.required),
            fisica: new FormControl(null),
            juridica: new FormControl(null),
        },
        toFormGroup: (obj: Pessoa): PessoaForm => {
            return {
                tipo: obj.tipo,
                fisica: obj.fisica,
                juridica: obj.juridica
            }
        },
        fromFormGroup: (formValue: PessoaForm): Pessoa => {
            return {
                tipo: formValue.tipo,
                fisica: formValue.fisica,
                juridica: formValue.juridica
            }
        }
    }) 

@maxime1992
Copy link
Contributor

Woups I forgot to reply completely here. Thanks for helping out @svenank3r!

@rlzdesenv as a complement to what @svenank3r said, you can find a few more usages in our demo app: https://github.com/cloudnc/ngx-sub-form/search?q=toFormGroup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants