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

setFormErrors for sub formGroup #1

Open
GiovaneRobertiTafine opened this issue Jun 21, 2022 · 2 comments
Open

setFormErrors for sub formGroup #1

GiovaneRobertiTafine opened this issue Jun 21, 2022 · 2 comments

Comments

@GiovaneRobertiTafine
Copy link

I'm having trouble setting the setFormErrors method in a sub group:

this.form = this.fb.group<ColaboradorCriar>({
            idEmpresa: [],
            colaborador: this.fb.group<Colaborador>({
                nomeCompleto: ["", [Validators.required]],
                email: ["", [Validators.required]],
                usuario: ["", [Validators.required]],
            })
        });

setFormErrors:

this.form.controls.colaborador.setFormErrors;

I've tried a few ways but I can't get the expected result.

@wilsonsergio2500
Copy link
Owner

@mandrilla34
I think the problem steams from the fact that accessing via the parent form is retrieved as an abstract control. one attempt perhaps could be.

const collaborador = this.fb.group<Colaborador>({
                nombreCompleto: ["", [Validators.required]],
                email: ["", [Validators.required]],
                usuario: ["", [Validators.required]],
            })

this.form = this.fb.group<ColaboradorCriar>({
            idEmpresa: [],
            colaborador: collaborador 
        });

collaborador.setFormErrors({
     nombreCompleto: {
        required: 'Esto es requerido..'
      }
     ....
})

Now consider also that setFormErrors is rather a helper function created to assist in the rendering of errors via the directive in the package... so this is no vanilla angular per se.

consider the following example

note the use of the directive in the mat-error, the vision was to be a common companion with the above declaration in order to reduce boilerplate.

Hope this helps

@GiovaneRobertiTafine
Copy link
Author

GiovaneRobertiTafine commented Jun 22, 2022

This is an good option, it opens a range of solutions but the access to these errors seems far away, as it contains a lot of handling to validate because in addition I have to change the directive in the formGroupName template that is used by default for these subgroups, to formGroup.

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

2 participants