-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Live] Adding a custom Stimulus controller to a live component #527
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
Comments
Hi Ryan, I stumbled upon the subject today.
This will unfortunately tie the ux code to Maybe we can add to this webpack bundle a filter
just throwing some ideas. |
Hello, I'm trying to link a custom controller to my Live Component. const component = document.getElementById('id-on-your-element').__component; While researching, I've found this current issue. And if it's possible, could you guide me to how to do it ? |
Hey @jbelien! Ok, 2 separate things here:
const element = document.getElementById('id-on-your-element');
element.addEventListener('live:connect', (event) => {
const component = event.detail.component;
}); That should be more reliable. You could also put this code into a Stimulus controller - https://symfony.com/bundles/ux-live-component/current/index.html#working-with-the-component-in-javascript - that goes around your live controller element. Let me know if this fixes it. We may need a warning in the docs about the other code that, if called too early, the component won't be there yet. |
Thanks A LOT @weaverryan for these clear(er) explanation. 😄
|
Awesome! Thank you for the update. In addition to fixing this bug, we should add a note/warning around the |
See #589 |
Sometimes you'll want to attach a stimulus controller to the root element of your live controller. Currently, you might try this:
But, I don't think that works, as I think we're always setting
data-controller
tolive
:ux/src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php
Line 102 in 2a49974
Also, that's a pretty ugly syntax, especially if you need to pass in some values 😱 .
What about one of the following:
stimulus_controller
returns a StimulusControllersDto which has atoArray()
method.The text was updated successfully, but these errors were encountered: