F
Filament17mo ago
Abi

Is there a way to trigger an action to launch a modal from the Livewire component class

Is there a way to trigger an action to launch a modal from the Livewire component class instead of triggering from a button?
10 Replies
Abi
AbiOP17mo ago
So I have a livewire method that authenticates the user and on successful authentication, I want to show a modal with a form for further actions.
LeandroFerreira
LeandroFerreira17mo ago
what code did you try? maybe using wire:init ?
Abi
AbiOP17mo ago
but I wasn't sure how to launch the modal from the Class the authentication happens on the Livewire class and I need to launch the modal from there
LeandroFerreira
LeandroFerreira17mo ago
is it a page action?
Abi
AbiOP17mo ago
so, here is what I have
public function login()
{
$this->validate([
'email' => 'required|email',
'password' => 'required'
]);

$response = Http::post('remote_api_url', [
'email' => $this->email,
'password' => $this->password,
'device_name' => 'web'
])->json();

if ($response['status'] === 'Success') {
//Trigger filament Action to Launch the modal with a form to get the license key and activate the app
}
}
public function login()
{
$this->validate([
'email' => 'required|email',
'password' => 'required'
]);

$response = Http::post('remote_api_url', [
'email' => $this->email,
'password' => $this->password,
'device_name' => 'web'
])->json();

if ($response['status'] === 'Success') {
//Trigger filament Action to Launch the modal with a form to get the license key and activate the app
}
}
Not sure what to do on the if block the login method is called on the wire:submit.prevent of the blade let me know if this makes sense I was trying something like Action::make('')->mount()
LeandroFerreira
LeandroFerreira17mo ago
are you using livewire3?
Abi
AbiOP17mo ago
yes
LeandroFerreira
LeandroFerreira17mo ago
I suppose you are using an Action on the Livewire component
//you have the action on the livewire component
public function customAction(): Action
{
return Action::make('customAction')
->action(function () {
//...
});
}

//you can listen for an event
#[On('actionFired')]
public function actionFired()
{
//when it is fired, you can open the modal...
$this->mountAction('customAction');
}


//dispatch the event..
if ($response['status'] === 'Success') {
$this->dispatch('actionFired')->to(YourComponent::class);
}
//you have the action on the livewire component
public function customAction(): Action
{
return Action::make('customAction')
->action(function () {
//...
});
}

//you can listen for an event
#[On('actionFired')]
public function actionFired()
{
//when it is fired, you can open the modal...
$this->mountAction('customAction');
}


//dispatch the event..
if ($response['status'] === 'Success') {
$this->dispatch('actionFired')->to(YourComponent::class);
}
Abi
AbiOP17mo ago
Ok, let me give this a try and get back to you. Thank you
Want results from more Discord servers?
Add your server