themesberg / flowbite

Open-source UI component library and front-end development framework based on Tailwind CSS
https://flowbite.com
MIT License
7.55k stars 715 forks source link

Listen to an HTML's button's associated modal's onShow event #643

Closed anjanesh closed 10 months ago

anjanesh commented 1 year ago
<button
    type="button"    
    data-modal-target="add-server-modal"
    data-modal-toggle="add-server-modal"    
>
    Add/Edit Server
</button>

I've created a modal using HTML and not having it popup using JavaScript's modal.show() I want to 'listen' to the above associated modal's (add-server-modal) on show event.

Is there a way to attach an event listener to the above HTML button's popup ?

EDIT : It seems like we can't combine data-modal-xxx with the event handlers in JavaScript. So the only route is to use onclick="modal.show()" inplace of data-modal-target="add-server-modal"

<button
    type="button"
    onclick="modal.show()"
>
    Add/Edit Server
</button>
zoltanszogyenyi commented 10 months ago

Hey @anjanesh,

You can do it now by using the new Instance Manager that we have introduced in v2.0

Learn more here:

https://flowbite.com/docs/getting-started/javascript/ https://github.com/themesberg/flowbite/releases/tag/v2.0.0

Cheers, Zoltan