Unable to get form errors from inside nested form group
See original GitHub issueIf you have a form group with nested form fields, how do you get the errors on those form fields?
If I bind a handler to the parent form, like this:
<formulate-input @validation="myValidationEvent"> ...
If I log the output from that event to the console, the output for a normal form field looks this this:
{name: 'personalDetails', errors: Array(1), hasErrors: true}
where errors
is an array containing the errors. But if I do the same for a form group, I get this:
{name: 'personalDetails', errors: Array(0), hasErrors: true}
Note the empty errors
array – this seems like a bug. How do I get to the errors on the form fields nested inside the group?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to validate error messages for nested form group fields in ...
Hi i am new for angular and i am trying to implement form validations and using below code and my problem is ...
Read more >FormGroupName - Angular
Use nested form groups to validate a sub-group of a form separately from the rest or to group the values of certain controls...
Read more >Angular Get Nested Form Errors - StackBlitz
import { FormArray, FormBuilder, FormGroup }. from '@angular/forms'. @Component({. selector: 'my-app',. template: ` check out console.log`. }).
Read more >Can't Bind to formGroup Not Known Property Error in Angular
If you don't import the right Angular form module in the right place, your code will fail to compile and you'll see Can't...
Read more >Angular Reactive Forms: Tips and Tricks | by Netanel Basal
For example, if you have an input that is bound to a form control, Angular performs the control validation process for every keystroke....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s an easy to use solution that gets you part of the way there, but not with the specific validation messages. If you put the
<FormulateErrors />
component near the bottom of your form (I usually do it right above the submit button) you can add a message to display when any errors are detected in the form and someone tries to submit. This is for this exact use case (long forms), but it falls short of actually delivering the specific messages that are failing. Partly this is by design since validation messages are written to be displayed in context. For example a validation message might something like “this field is invalid” which is unhelpful when it’s displayed in a rollup at the bottom of the screen.If you really need to show the specific messages though, you’ll need to do some work like binding to the
@validation
handler or using aref
to get a hold of the context object explicitly to access them.@henryaj I had this same issue (I need to display a list of all errors in the form). The solutions provided above just don’t work well for grouped data.
I created a custom component that loops over the
failingFields
data of the form to create a list of errors. To get the form errors data, I created a simple watcher like this:You can then use the
failingFields
data to help list out the errors. Obviously your use case will need more work on top, but hopefully, this helps. Let me know if you need more info