symfony / ux

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

[ux-components] on load page trigger event add ? #2189

Open xorgxx opened 4 hours ago

xorgxx commented 4 hours ago

Hi, I've tried many different solutions for this issue link to discussion.

It seems that while the controller.js is being loaded (as confirmed by the console log), the "event" isn't being triggered when the page loads.

I'm stuck at this point and wondering if it's the same issue. Any insights?

xorgxx commented 3 hours ago

It seems that I’ve found a solution, though I’m not sure if it’s the best approach since I haven’t seen this documented anywhere 👍

<div {{ stimulus_controller('@xorgxx/neox-dashboard-bundle/neox-modal') }}>
    <button data-action="click->xorgxx--neox-dashboard-bundle--neox-modal#modal">Open Modal</button>
</div>

To declare the controller, use {{ stimulus_controller('@xorgxx/neox-dashboard-bundle/neox-modal') }}, but for the data-action, use "click->xorgxx--neox-dashboard-bundle--neox-modal#modal". i find this strange no ?

xorgxx commented 2 hours ago

!!!! It might be worth considering modifying the page /create_ux_bundle.html to clearly highlight that the link

<div {{ stimulus_controller('@xorgxx/neox-dashboard-bundle/neox-modal') }}>
    <button data-action="click->xorgxx--neox-dashboard-bundle--neox-modal#modal">Open Modal</button>
</div>

stimulus_controller('@xorgxx/neox-dashboard-bundle/neox-modal') is automatically handled and "transformed," whereas other instances like data-action="click->xorgxx--neox-dashboard-bundle--neox-modal#modal"you need to be set up manually.