-
-
Notifications
You must be signed in to change notification settings - Fork 364
[LiveComponent] Tweak live collection rendering #421
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
Conversation
ad02c31
to
a8c60b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot! Would you mind adding a small section to the docs with an example of overriding live_collection_widget
(e.g. to render the add button first then the widget) and live_collection_entry_row
. (e.g. to add a <div>
around each row)?
Thanks! I will. |
'data-action-name': 'addCollectionItem(name=' ~ form.vars.full_name ~ ')' | ||
}) }) }} | ||
{%- if skip_add_button|default(false) is same as false and button_add_prototype is defined and not button_add_prototype.rendered -%} | ||
{{ form_row(button_add_prototype) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing the name of the exposed variable to button_add
or maybe something more specific to the collection live_collection_item_add
or just item_add
?
skip_add_button
, button_add
, button_delete
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_button
, delete_button
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I kind of like button_add
and button_delete
better, but not sure about it 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I've left some questions about the docs - my form theming is a bit fuzzy :)
|
||
If you want more control over how each row is rendered you can override the blocks | ||
related to the ``LiveCollectionType``. This works the same way as for `the traditional | ||
collection type`_, but you should use ``live_collection`` and ``live_collection_entry`` as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean live_collection_widget
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just meant to mention it's just a prefix, it can be live_collection_widget
, live_collection_row
, live_collection_errors
, ... and linked the docs for the collection field (https://symfony.com/doc/current/form/form_themes.html#fragment-naming-for-collections). Maybe better to write live_collection_*
instead.
|
||
.. code-block:: twig | ||
|
||
{%- block _blog_post_form_comments_widget -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this live_collection_widget
? I mean, I know what you have is correct for this situation, but I think showing live_collection_widget
would be better (it would be very rare someone would need to override LiveCollectionType
twice in the same form in a different way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant this could be an example for customizing just for a specific form type, and the next with the bootstrap table could be a generic one. But it's fine by me to keep it simple and just use live_collection_widget
here too.
<tr> | ||
{% for child in form|filter(child => not child.rendered) %} | ||
<td>{{- form_row(child, { label: false }) -}}</td> | ||
{% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a clever way to loop over all of the fields in the sub-form and render them? If so, what's the purpose of the |filter(child => not child.rendered
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this just renders the children in a <td>
. It's safer to use in this way, because if a field was rendered already, rendering it again will throw an exception. But in this case it's not really necessary, so I leave it out.
aa68ee3
to
0fa9688
Compare
0fa9688
to
e174a28
Compare
Thank you Gábor! |
…erryan) This PR was merged into the 2.x branch. Discussion ---------- [LiveComponent] Minor docs tweaks and changelog bump | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | Minor tweaks after #421 | License | MIT Commits ------- a405475 [LiveComponent] Minor docs tweaks and changelog bump
Thank you! |
Uh oh!
There was an error while loading. Please reload this page.