F
Filament4mo ago
ericmp

How to call action from js?

I have a custom script in a custom filament page. Inside of it, when something happens, i want to open an action. I'm trying:
// js
mountAction('createTask')
// js
mountAction('createTask')
but i get: Uncaught ReferenceError: mountAction is not defined this is the action, and if i click it's button, it triggers it and the modal gets opened. so i just wanna call the method that opens the action modal via js:
public function createTaskAction(): Action
{
return Action::make('createTask')
->form([
Forms\Components\TextInput::make('name'),
])
->action(function (array $arguments): void {
dd('hi');
})
;
}
public function createTaskAction(): Action
{
return Action::make('createTask')
->form([
Forms\Components\TextInput::make('name'),
])
->action(function (array $arguments): void {
dd('hi');
})
;
}
5 Replies
LeandroFerreira
LeandroFerreira4mo ago
maybe $wire.mountAction('createTask') ?
ericmp
ericmp4mo ago
VM38393:1 Uncaught ReferenceError: $wire is not defined at <anonymous>:1:1 what im missing? i just called it in the browser js console
awcodes
awcodes4mo ago
Laravel
JavaScript | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
ericmp
ericmp4mo ago
now i just tried to add it in the script instead of via browser js console, same error checking it out now yeah, but idk how to call the mountAction method yet, ill keep seraching is mountAction is a function of the livewire component? and i pass in an argument which is the action name cant use $wire in this particular script, cuz is inside a wire:ignore i've finally achieved it. now i have different 2 scripts one inside the @script @endscript so it can access $wire and the other one in the wire ignore so the feature can work omg kinda tricky but works thanks y'all!