F
Filament6d ago
Liam

Open another form modal from a form modal

https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#chaining-actions I have a CreateAction that lets users create personal access tokens. After the token is created, I want to close the modal and show a new modal with the plain text token so they can copy it and only see it once. I know we can chain actions in Filament PHP, but I get an error when I try to pass the token to a form. Could anyone help or share a suggestion? Thank you!
Solution:
What about this? ```php public function createAction(): Action {...
Jump to solution
7 Replies
Dennis Koch
Dennis Koch6d ago
but I get an error when I try to pass the token to a form.
It would help if you'd share the error and some code.
Liam
LiamOP6d ago
public function showTokenAction(): Action
{
return Action::make('showToken')
->modalHeading(__('Your personal access token'))
->modalContent(function () {
return view('filament.pages.actions.token-modal', [
'plainTextToken' => $this->plainTextToken,
]);
})
->modalWidth(MaxWidth::Large);
}
public function showTokenAction(): Action
{
return Action::make('showToken')
->modalHeading(__('Your personal access token'))
->modalContent(function () {
return view('filament.pages.actions.token-modal', [
'plainTextToken' => $this->plainTextToken,
]);
})
->modalWidth(MaxWidth::Large);
}
` I kinda got it working (the modal opens after my initial action form), but the plainTextToken is null in my view. When I do dd($this->plainTextToken) before the "return view()" then it works fine. But for some reason it doesn't get passed to the view, and I can't figure out why.
Liam
LiamOP6d ago
Interesting, it seems like the data is unavailable again once the form opens.
No description
Dennis Koch
Dennis Koch6d ago
$this probably refers to the action. Try injecting $livewire into to closure and use that
Liam
LiamOP4d ago
Same issue unfortunately
Solution
LeandroFerreira
What about this?
public function createAction(): Action
{
return Action::make('create')
->form([
TextInput::make('token')
->required(),
])
->action(function (array $data) {

// Here you can handle the form submission

$this->replaceMountedAction('showToken', $data);
});
}

public function showTokenAction(): Action
{
return Action::make('showToken')
->fillForm(fn (array $arguments): array => [
'token' => $arguments['token'],
])
->form([
TextInput::make('token')
->disabled(),
])
->modalSubmitAction(false)
->modalCancelActionLabel('Close');
}
public function createAction(): Action
{
return Action::make('create')
->form([
TextInput::make('token')
->required(),
])
->action(function (array $data) {

// Here you can handle the form submission

$this->replaceMountedAction('showToken', $data);
});
}

public function showTokenAction(): Action
{
return Action::make('showToken')
->fillForm(fn (array $arguments): array => [
'token' => $arguments['token'],
])
->form([
TextInput::make('token')
->disabled(),
])
->modalSubmitAction(false)
->modalCancelActionLabel('Close');
}
Liam
LiamOP4d ago
Yes this works, thanks!

Did you find this page helpful?