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

[LiveComponent] Add Documentation for testing with LiveCollectionType #2517

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from

Conversation

yalit
Copy link
Contributor

@yalit yalit commented Jan 21, 2025

Q A
Bug fix? no
New feature? no
Issues Fix #2512
License MIT

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

$component->call('addCollectionItem', ['name' => 'children']);
//... can be called as many times as you need entries in your 'children' field

// and then submit the form
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// and then submit the form
// ... then submit the form by providing data for all the fields in the ChildFormType:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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::
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link
Contributor Author

@yalit yalit Jan 22, 2025

Choose a reason for hiding this comment

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

Indeed more descriptive and I would add at the end of your updated comment : "before submitting it"

Copy link
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

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

Some minor details to fix (if you agree), very nice addition, thank you!

@smnandre smnandre added docs Improvements or additions to documentation LiveComponent DX labels Jan 22, 2025
@smnandre smnandre changed the title Doc/addition of documentation for testing with live collection type [LiveComponent] Add Documentation for testing with LiveCollectionType Jan 22, 2025
@yalit
Copy link
Contributor Author

yalit commented Jan 22, 2025

Thanks for the review which makes full sense. I'll look at it today.

yalit added 2 commits January 22, 2025 08:55
- better english ;-)
- clearer description of steps
- better use of RST (double backticks instead of single ;-))
@yalit
Copy link
Contributor Author

yalit commented Jan 22, 2025

Updates made based on the review and updated proposals

Copy link
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

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

Thank you @yalit !

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jan 22, 2025
Copy link
Contributor

@94noni 94noni left a comment

Choose a reason for hiding this comment

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

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)
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
->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],
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
['name' => 'childName1', 'age' => 10],
['firstName' => 'childName1', 'age' => 10],
['firstName' => 'childName2', 'age' => 15],

@yalit
Copy link
Contributor Author

yalit commented Jan 24, 2025

may I propose to use another field name, to not overlap with the

$component->call('addCollectionItem', ['name' => 'children']);

wdyt?

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation DX LiveComponent Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with test submitForm with LiveCollectionType
4 participants