FilamentF
Filament9mo 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?

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');
}
Was this page helpful?