wire-elements / modal

Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
MIT License
1.11k stars 131 forks source link

JS not working inside modal, that previously worked in V2 #350

Closed jsznap closed 1 year ago

jsznap commented 1 year ago

Using plugins that are globally imported like pikaday/flatpickr/zoomist are not accessible or do not operate inside livewire 3 modals.

Just a basic function like : <script> var datepick = document.getElementById("showing_date_modal"); // console.log(datepick); var modalPicker = new pikaday({ field: datepick, format: 'MM/DD/YYYY' }) </script>

Works when included in a livewire component but isn't working inside a livewire modal. I already have the include_js disabled and i am including the wire-elements resource in my app.js.

jsznap commented 1 year ago

Had to put JS on app layout and use a livewire event in a rendered lifecycle hook to trigger it. Loading it inside the modal did not trigger it.

PhiloNL commented 1 year ago

I believe <script> wouldn't work in v2 either. You would have to use Alpine to ensure javascript is executed, for example:

<div x-data x-init="var modalPicker = new pikaday({ field: datepick, format: 'MM/DD/YYYY' })">
</div>
ignacioOptinet commented 1 year ago

That used to work in v2, 100%.