[LiveComponent] Add Documentation for testing with LiveCollectionType#2517
Conversation
| $component->call('addCollectionItem', ['name' => 'children']); | ||
| //... can be called as many times as you need entries in your 'children' field | ||
|
|
||
| // and then submit the form |
There was a problem hiding this comment.
| // and then submit the form | |
| // ... then submit the form by providing data for all the fields in the ChildFormType: |
There was a problem hiding this comment.
Looking at the next review, I would add at the end of your updated comment for each added entry or something of sort
| } | ||
| } | ||
|
|
||
| The test of the submission of such form would be with the TestHelper:: |
There was a problem hiding this comment.
| The test of the submission of such form would be with the TestHelper:: | |
| Use the addCollectionItem method from the LiveCollectionTrait to dynamically add entries to the children field of the form: |
There was a problem hiding this comment.
Indeed more descriptive and I would add at the end of your updated comment : "before submitting it"
smnandre
left a comment
There was a problem hiding this comment.
Some minor details to fix (if you agree), very nice addition, thank you!
|
Thanks for the review which makes full sense. I'll look at it today. |
|
Updates made based on the review and updated proposals |
94noni
left a comment
There was a problem hiding this comment.
may I propose to use another field name, to not overlap with the
$component->call('addCollectionItem', ['name' => 'children']);
wdyt?
| public function buildForm(FormBuilderInterface $builder, array $options): void | ||
| { | ||
| $builder | ||
| ->add('name', TextType::class) |
There was a problem hiding this comment.
| ->add('name', TextType::class) | |
| ->add('firstName', TextType::class) |
| // ... then submit the form by providing data for all the fields in the ChildFormType for each added entry: | ||
| $component->submitForm([ 'live_collection_form' => [ | ||
| 'children' => [ | ||
| ['name' => 'childName1', 'age' => 10], |
There was a problem hiding this comment.
| ['name' => 'childName1', 'age' => 10], | |
| ['firstName' => 'childName1', 'age' => 10], | |
| ['firstName' => 'childName2', 'age' => 15], |
@94noni, for me it's indeed better, nice update. As it doesn't change the information of the doc but improves it (in my opinion), I would assume it's ok for @smnandre (I can do the update today). As already approved, can you confirm from your side? |
f884f27 to
fd208f8
Compare
|
Thank you @yalit. |
As mentioned in the #2512, I had trouble testing the submission of a form containing a LiveCollectionType field due to lack of proper guidance in the documentation. Hence this pull request to propose an addendum in the documentation linked to that capability