Best way to inject a third party javascript asset just for one RelationManager form() ?
I have this code in AdminPanelProvider's boot():
This injects Stripe into my system. However, I only really want to do this where I am actually using Stripe and not on every single page as I do currently.
I use the Stripe JavaScript library in one location: app/Filament/Resources/Member/RelationManagers/SubscriptionsRelationManager.php's form() method.
The code in form() is:
The view forms.components.stripe-card contains x-data which utilises the Stripe JavaScript library.
Where would you propose I put the inclusion of the Stripe JavaScript library? Thanks.
Solution:Jump to solution
So you'll want lazy loading the assets. See:
https://filamentphp.com/docs/4.x/advanced/assets#lazy-loading-javascript...
2 Replies
Solution
So you'll want lazy loading the assets. See:
https://filamentphp.com/docs/4.x/advanced/assets#lazy-loading-javascript
Thanks @toeknee , this looks great. I changed my code in AdminPanelProvider to:
Unfortunately my x-data code expects Stripe to exist on load of init(), which it doesn't yet.
Is there an event that tells me the asset has been registered? I would listen for this event somehow and call my Stripe code within the listener.
I solved this by doing: