question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

markAllAsTouched() not propegated to subforms

See original GitHub issue

Repro:

  • One root form A with sub form B
  • Submit button on root form can always be clicked
    • Submit calls markAllAsTouched()

Expected:

  • all fields on the entire form tree incl sub-forms should be touched

Actual:

  • only controls directly on the root form are being marked as touched

Note:

  • I assume it does not work as the sub-form is only connected to the root form via value accessor
  • and looking at the value accessor interface, touched is not an event that gets propagated from parent to child (only the other way around registerOnTouched)

The intent of this issue is to try and come up with a best practice to handle this and if possible to extend the library to assist in these cases.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
maxime1992commented, May 13, 2020

Can we all please give a 👍 to the following issue: https://github.com/angular/angular/issues/27315 ?

If that was solved upstream we could implement this feature really easily ❤️

1reaction
agallardolcommented, Nov 3, 2020

Hi everyone, today I was dealing with this problem and trying to use your ideas as inspiration I created the following gist that let me workaround the markAsTouched/markAllAsTouched problem.

NgxSubForm markAllAsTouched fix

All of your feedback is very preciated and I hope this could help someone of you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Both markAllAsTouched and markAsTouched don't affect ...
And the events triggered on the form group would propagate through the sub forms. Example code. parent.component.ts this.form = this.
Read more >
Best Way To Use markAllAsTouched in Angular Forms
First, we target forms that have the formGroup directive. Next, we obtain a reference to the FormGroupDirective instance via dependency ...
Read more >
Angular: Nested Reactive Forms Using ... - Medium
In this post, we will see how to implement nested reactive forms using composite control value accessors(CVAs). Kara Erickson of the Angular Core...
Read more >
Angular Custom Form Controls - Complete Guide
Build a fully functional custom form control, compatible with template-driven and reactive forms, as well as with all built-in and custom ...
Read more >
Quick Tip for Angular Forms: Keep your markAllAsTouched DRY
And in each submit handler you've called markAllAsTouched() to cover cases where users didn't touch one of the fields: We can automate this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found