F
Filament6mo ago
Azorky

How can I change the redirect url of the cancel button on the create page?

When I'm on the create page and I press the cancel button I get automatically redirected to the resource's list page. I don't want that, instead I want to be able to customize where the user is redirected after cancelling. How can I do that?
2 Replies
Vp
Vp6mo ago
I am not really sure how to change "cancel button redirect", but I have a similar like this and this is how I come up (inside create page)
protected function getFormActions(): array
{
return [
parent::getFormActions()[0], // create button

Action::make('reset')
->label(__('Reset')),
];
}
protected function getFormActions(): array
{
return [
parent::getFormActions()[0], // create button

Action::make('reset')
->label(__('Reset')),
];
}
Azorky
Azorky6mo ago
Thanks for the tip. I used this to make the cancel button redirect to itself, causing the screen to refresh:
protected function getFormActions(): array
{
return [
Actions\CreateAction::make()
->submit('save')
->label('Aanmaken'),
Actions\Action::make('cancel')
->label('Annuleren')
->color('gray')
->url($this->getResource()::getUrl('create', ['project' => $this->project->id])),
];
}
protected function getFormActions(): array
{
return [
Actions\CreateAction::make()
->submit('save')
->label('Aanmaken'),
Actions\Action::make('cancel')
->label('Annuleren')
->color('gray')
->url($this->getResource()::getUrl('create', ['project' => $this->project->id])),
];
}