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

Nested forms #100

Closed
grosch opened this issue Jul 30, 2021 · 2 comments
Closed

Nested forms #100

grosch opened this issue Jul 30, 2021 · 2 comments

Comments

@grosch
Copy link

grosch commented Jul 30, 2021

I'm submitting a...


[X] Support request

Current behavior

I'm using this with nested components where each child component is a CVA that has its own FormGroup. Right now I'm doing something like this, which just feels wrong.

    @ViewChild(DetailGeneralComponent) private general!: DetailGeneralComponent

    ngOnInit(): void {
        this.formGroup = this.fb.group({
            general: this.fb.group<IDetailGeneralForm>({
                manager: undefined,
                delegate: undefined,
                linkUrl: undefined,
                linkTitle: undefined
            })
        })

        const id = +this.route.snapshot.params['id']
    }

    ngAfterViewInit(): void {
        this.formGroup.setControl('general', this.general.formGroup)
    }

Expected behavior

Having to fully define the 'general' control here feels wrong since I'm going to just replace it with the actual form group from the child. Is there a better way to be doing this? Because it's now properly typed, it seems like I need to do that.

@grosch
Copy link
Author

grosch commented Aug 12, 2021

Any help you can provide here?

NetanelBasal added a commit that referenced this issue Oct 8, 2021
BREAKING CHANGE: refactor the entire code

I completely rewrote the library from scratch for two reasons:
1. Provide as much support as possible without introducing bugs, breaking strict mode, or creating an inconvenient API.
2. Reduce the library size.

Here are the changes:
- Angular's peer dependency is now `>= 12`.
- FormGroup's generic was removed in favor of the **experimental** `ControlsOf` interface.
- Remove `mergeValidators`.  Use addValidators in v12.
- Remove `validateOn`.
- Remove `getControl` in favor of `get(key)` or `get(['nested', 'key'])`.
- Remove errors typing.
- Validators should now be imported from Angular.
- `FormBuilder` doesn't support generic anymore. Due to the complexity of the builder API, we're currently couldn't create a "good" implementation of `ControlsOf` for the builder.
- Remove the `group.persist()` from the instance to an exported function to make it tree-shakeable.

Fixes #197,#103,#102,#97,#100
@NetanelBasal
Copy link
Member

I am closing this issue as I released v3.

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