symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
845 stars 310 forks source link

[Doc] Little error on form-collection-type demo #2033

Closed Nek- closed 2 months ago

Nek- commented 2 months ago

From what I understand, the following instantiateForm is useless:

https://github.com/symfony/ux/blob/e122096cead156c2e1608976a6a69a887fd3b1a0/ux.symfony.com/src/Twig/TodoListForm.php#L32-L38

The form is actually instantiated here:

https://github.com/symfony/ux/blob/e122096cead156c2e1608976a6a69a887fd3b1a0/ux.symfony.com/src/Controller/Demo/LiveComponentDemoController.php#L50

It's pretty disturbing while reading the doc 😅

norkunas commented 2 months ago

But the controller is not reached at all when the component rerenders, so it needs to know which form to instantiate

smnandre commented 2 months ago

That's why this method must be implemented (it's an abstract method of the ComponentWithFormTrait, used in the LiveCollectionTrait)

See here: https://github.com/symfony/ux/blob/21595a73e74c0ef1a3a14f8697b48580e6b07488/src/LiveComponent/src/ComponentWithFormTrait.php#L68

Nek- commented 2 months ago

The form is passed here:

https://github.com/symfony/ux/blob/e122096cead156c2e1608976a6a69a887fd3b1a0/ux.symfony.com/templates/demos/live_component/form_collection_type.html.twig#L12

And it's not in the doc besides it seems required.

smnandre commented 2 months ago

I'm not sure to understand.. the documentation states the following in the "ComponentWithFormTrait" section

The trait forces you to create an instantiateForm() method, which is used each time the component is rendered via AJAX. To recreate the same form as the original, we pass in the initialFormData property and set it as a LiveProp.

https://symfony.com/bundles/ux-live-component/current/index.html#rendering-an-entire-form-in-a-component

How would you improve things ? :)