Skip to content

[LiveComponent] Add Documentation for testing with LiveCollectionType#2517

Merged
smnandre merged 1 commit into
symfony:2.xfrom
yalit:doc/addition-of-documentation-for-testing-with-live-collection-type
Feb 7, 2025
Merged

[LiveComponent] Add Documentation for testing with LiveCollectionType#2517
smnandre merged 1 commit into
symfony:2.xfrom
yalit:doc/addition-of-documentation-for-testing-with-live-collection-type

Conversation

@yalit
Copy link
Copy Markdown
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

Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst
Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst Outdated
$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
Copy Markdown
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
Copy Markdown
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

Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst Outdated
}
}

The test of the submission of such form would be with the TestHelper::
Copy link
Copy Markdown
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
Copy Markdown
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"

Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst Outdated
Comment thread src/LiveComponent/doc/index.rst Outdated
Copy link
Copy Markdown
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 Documentation 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
Copy Markdown
Contributor Author

yalit commented Jan 22, 2025

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

@yalit
Copy link
Copy Markdown
Contributor Author

yalit commented Jan 22, 2025

Updates made based on the review and updated proposals

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@smnandre smnandre force-pushed the doc/addition-of-documentation-for-testing-with-live-collection-type branch from f884f27 to fd208f8 Compare February 7, 2025 23:11
@smnandre
Copy link
Copy Markdown
Member

smnandre commented Feb 7, 2025

Thank you @yalit.

@smnandre smnandre merged commit 8fdcd69 into symfony:2.x Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation 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