script in modalContent(view('qr-scanner.php')) not working
Hello I am trying to integrate this package into filament action modal
https://github.com/mebjas/html5-qrcode
the console log in the script works only when called from a web.php route. the script doesnt execute when implemented through modalContent(view()). how can i solve this? any ideas would also be helpful. Thank you.
GitHub
GitHub - mebjas/html5-qrcode: A cross platform HTML5 QR code reader...
A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org - mebjas/html5-qrcode
16 Replies
bump
Try to register the JS using this
https://filamentphp.com/docs/3.x/support/assets/#registering-javascript-files-from-a-url
In a form this is probably the issue, as the DOM is already loaded:
document.addEventListener("DOMContentLoaded", function() {
you could also use
alpine
thanks for the reply. I have tried it this way. The script runs but I have not been able to get the html5Qrcodescanner object.
Heres my code
I have been trying to figure out how to get Html5Qrcode objects inside init function
The script tag doesnt seem to run when used from Action modalContent. I have tried using a different event but the script simply doesnt execute
However the same code works pretty well when routed directly from web.php. the script works fine and the components are loaded
I don't know why you need to dispatch an event if you can use the x-init in the modal content..
just trying different approaches to figure out which one works
did you try my code?
@Leandro Ferreira of course this is the version
could you share the modal content?
sorry I didn't notice that..
Did you register the js as I mentioned?
remove imports and use this 👆
Solution
add to the appserviceprovider
this one did the job. Sorry I missed it earlier
hello, I am trying a few more things to complete the feature. I need to programatically close the modal on success. But I am unsure of how to set/get modal id? Can you give me an idea on how to accomplish this?
got this
https://discord.com/channels/883083792112300104/1273718758812422215
I have tried implementing your code but the modal doesn't yet close for some reason
the modalID is correctly extracted.