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

docs: add sample usage of the FormArray API for reactive forms #54138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

maequise
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Missing a more concrete sample on how to use the FormArray API

Issue Number: #53705

What is the new behavior?

Include a more concrete sample of how to use the FormArray API on the site into the guide of reactive forms

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@jessicajaniuk jessicajaniuk added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: adev Angular.dev documentation adev: preview labels Jan 29, 2024
@ngbot ngbot bot modified the milestone: Backlog Jan 29, 2024
@jessicajaniuk
Copy link
Contributor

@maequise Looks like your commit message is causing the lint to fail. It's very close though. Run git commit --amend and change your commit message to docs: add sample usage of the FormArray API for reactive forms, and then force push. That'll fix it.

@jessicajaniuk
Copy link
Contributor

@dylhunn Can you review the content here?

Copy link

github-actions bot commented Jan 29, 2024

Deployed adev-preview for 9a09d02 to: https://ng-dev-previews-fw--pr-angular-angular-54138-adev-prev-6sk3qzg2.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@angular-robot angular-robot bot added the area: docs Related to the documentation label Jan 29, 2024
@jessicajaniuk jessicajaniuk changed the title (docs): add sample usage of the FormArray API for reactive forms docs: add sample usage of the FormArray API for reactive forms Jan 29, 2024
selector: 'my-form-comp',
standalone: true,
imports: [ReactiveFormsModule]
//component declaration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not revelant, I certainly forgot to remove it. If need I can remove it and make a new push.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, remove anything that is not relevant.

@@ -392,6 +392,192 @@ Initially, the form contains one `Alias` field. To add another field, click the

</docs-workflow>

## A more concrete usage of FormArray

In a more concrete sample, we can imagine the following use case. You are application needs a basic form, with known information, but the user has the ability to add more or less sub-form.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In a more concrete sample, we can imagine the following use case. You are application needs a basic form, with known information, but the user has the ability to add more or less sub-form.
In a more concrete sample, we can imagine the following use case. Your application needs a basic form, with known information, but the user has the ability to add more or less sub-form.


And in the template we have our principal form displayed and mapped, and a `@for` loop used to iterate over the `FormArray`.

Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` directly with the **get()** method. We will define a getter method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` directly with the **get()** method. We will define a getter method.
Tip: If you watch the HTML template, you will notice that the access to the `FormArray` is not from the `FormGroup` but directly using the **get()** method. We will define a getter method.

}
}
```
With this method, when the user click on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With this method, when the user click on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated.
With this method, when the user clicks on the button, it is adding a new `FormGroup` in the `FormArray`. When adding a new entry, the template will be updated.


<docs-step title="Add possibility to remove an entry">

We can add entries to the `FormArray` but we should be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We can add entries to the `FormArray` but we should be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`.
We can now add entries to the `FormArray` but we should also be able to remove a specific entry. The `FormArray` has the **removeAt()** method that permits to delete a specific index of the `FormArray`.

@maequise
Copy link
Author

@sonukapoor thank you for the review, I made the corrections (the last forced "push" was because I missed one edit)

@MarkTechson
Copy link
Contributor

I really appreciate this work but this should really be a tutorial or code example, not necessarily an additional guide. I would also add here that we should consider revamping this guide and converting it to an issue that we should track and keep track of this work.

@twerske can you chime in on this?

@maequise
Copy link
Author

I really appreciate this work but this should really be a tutorial or code example, not necessarily an additional guide. I would also add here that we should consider revamping this guide and converting it to an issue that we should track and keep track of this work.

@twerske can you chime in on this?

I was thinking earlier in the afternoon adding a tutorial on the suject.

@twerske
Copy link
Contributor

twerske commented Feb 1, 2024

I really appreciate this work but this should really be a tutorial or code example, not necessarily an additional guide. I would also add here that we should consider revamping this guide and converting it to an issue that we should track and keep track of this work.

@twerske can you chime in on this?

I agree. This should be a tutorial not a guide since it's a walk through of a code example.

@maequise
Copy link
Author

maequise commented Feb 4, 2024

As suggested, I made a tutorial for this part and removed the guide part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer adev: preview area: adev Angular.dev documentation area: docs Related to the documentation target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants