-
-
Notifications
You must be signed in to change notification settings - Fork 312
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] Embeded stimulus controller in a live form not working on re-render #489
Comments
Hi @tdumalin! Thanks for the reproducer! That was super helpful! This is definitely an area we want to make smoother, even if it's just via documentation. In this case, when the Stimulus controller's When the component re-renders, we have 2 options: A) We make sure to NOT overwrite these changes - i.e. we add As you guessed, (A) is definitely the first thing to try. I added it to the For (B), what we can do is force LiveComponents to TOTALLY re-render the "date" field instead of just "modifying the things inside that changed". This will trigger the Another interesting approach might be to combine the two - e.g. Cheers! |
Hi @weaverryan Thanks for the help, i tried to apply your advice, with data-live-id containing an unique value, the datepicker can now be used after a re-render but the value of the field is lost on each re-render triggered by another form field. Some changes:
|
Hi @tdumalin! Ok, I see your random About the problem, it's a classic problem with external JavaScript: https://symfony.com/bundles/ux-live-component/current/index.html#updating-a-field-via-custom-javascript With a normal input field, when you change it, it triggers a It strikes me that, as this will be common, we'll want to offer SOME better way to work around this limitation in libraries. |
Exactly what i need to know ! thank you for all your explanation, the way live component works is way more clear now. Use the data-live-id="{{ random() }}" is some kind of weird, i would say that you should add an attribute called "data-rerender-behavior" with string value like: always|never|onChange Thanks again for the help ! |
Thanks for the suggestion - I opened an issue at #490 - but I wasn't sure what you had in mind for the |
Hi,
I want to use symfony live component to render a form and use some other controller embeded in the form.
Some example may be to use a datepicker. I used this one: https://www.npmjs.com/package/stimulus-datepicker
I've managed to use the controller in the form but when i change an input the component re-render is triggered and the stimulus controller doesn't work anymore.
A solution may be to use data-live-ignore but in my project i use this picker in a LiveCollectionType entry so i need the controller to be connected after a re-render
I've created a mini project to show the problem:
https://github.com/tdumalin/bug-live-component.git
Installation (assumes that php, symfony cli,composer and yarn are installed):
http://127.0.0.1:8000/
When you click on "Toggle" the picker shows but if you change the select value and re-click on "Toggle" stimulus controller is not triggered anymore
The text was updated successfully, but these errors were encountered: