Script Doesnt Load When Using Modals
I created a filament custom field. It needs an external script to work so i add it at the bottom of the component
So far works, cool.
But now im using the field in a modal. and there, it doesnt work. the script is not being loaded.
so the question is, how to load the script when the field is inside a modal?
i've tried to remove the async and defer, but the result is the same:
11 Replies
now i tried to follow this - https://github.com/filamentphp/filament/discussions/12614#discussioncomment-9313600
but still getting the same error
bump
the script is not being loaded.Is it really not being loaded or just after your code is run?
just checked it, is not being loaded
i did it by using the js browser console, i get the same error
if it was loaded i guess i would be able to execute functions that the script provides
i also tried @push('scripts') but nah, same error
You don’t need to execute this script every time a modal is loaded. Instead, add the script to the provider
You can run your code in the custom field using Alpine.js.
im on v2 + only forms + tables separated components (no admin panels)
is it fine? or the code u provide is for panels?
use
https://filamentphp.com/docs/2.x/admin/appearance#including-frontend-assets
custom field is the same I think
i think that is for panels, since i get
Undefined type 'Filament\Facades\Filament'
(im not using admin panel)if you are not using panels, you should register the script in your layout
https://filamentphp.com/docs/2.x/forms/installation#configuring-layout
yeah but this script is only called in a modal in a specific table, everywhere else where i call the layout ill be downloading the script but i dont need it
but if this is the workaround i think ill have to do that
you can use
@push('scripts')
to register the script, but outside the modal
https://laravel-livewire.com/docs/2.x/inline-scripts#introductionLivewire
Inline Scripts | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
the thing is that the cdn is inside a custom field xd
well dont worry, at the moment ill add the cdn call on the views that i use the field
appreciate ur time