How to reorder button on edit resource

Is it possible to reorder buttons on edit reource that mine primary button is right and cancel button is left
No description
Solution:
Very quick and simple way would be to edit the EditPage.php and add: ```php...
Jump to solution
20 Replies
mile4841
mile4841OP6mo ago
I would like to look like on the picture bellow
No description
Solution
toeknee
toeknee6mo ago
Very quick and simple way would be to edit the EditPage.php and add:
protected function getFormActions(): array
{
return array_reverse(parent::getFormActions());
}
protected function getFormActions(): array
{
return array_reverse(parent::getFormActions());
}
mile4841
mile4841OP6mo ago
Thanks man it works :fi:
mile4841
mile4841OP6mo ago
Do you maybe know how i can rename the save text button i try with
protected function getFormActions(): array
{
$inputs = array_reverse(parent::getFormActions());
$inputs[1]->label = 'Save changes and keep editing'; // i get the error here: label is protected
return $inputs;
}

protected function getFormActions(): array
{
$inputs = array_reverse(parent::getFormActions());
$inputs[1]->label = 'Save changes and keep editing'; // i get the error here: label is protected
return $inputs;
}

tesse05
tesse056mo ago
in "getFormActions()" you can pass manually an array of actions. just put manually the CancelAction::make() and SaveAction::make()->label('new text')
mile4841
mile4841OP6mo ago
what is the namespace for the CancelAction and SaveAction
tesse05
tesse056mo ago
do it like this:
use Filament\Pages\Actions\Action;
...
Action::make('close')
->label('Close')
->cancel(),
Action::make('submit')
->label('Save ...')
->submit(),
use Filament\Pages\Actions\Action;
...
Action::make('close')
->label('Close')
->cancel(),
Action::make('submit')
->label('Save ...')
->submit(),
mile4841
mile4841OP6mo ago
I get the error for the cancel()
tesse05
tesse056mo ago
which error
mile4841
mile4841OP6mo ago
No description
mile4841
mile4841OP6mo ago
just these and then mark cancel function
tesse05
tesse056mo ago
are you in the EditPage?
mile4841
mile4841OP6mo ago
app/Filament/Resources/MineResource/Pages/EditResource.php this is mine path where i paste your code
tesse05
tesse056mo ago
my fault, ->cancel() is only for modalActions, I think.. do this, it works:
$this->getCancelFormAction(), Action::make('submit')
->label('Save ...')
->submit(),
$this->getCancelFormAction(), Action::make('submit')
->label('Save ...')
->submit(),
or:
$this->getCancelFormAction(), $this->getSaveFormAction()->label('new label')
$this->getCancelFormAction(), $this->getSaveFormAction()->label('new label')
toeknee
toeknee6mo ago
Just replace the actions with a clone of the save and cancel actions...
protected function getFormActions(): array
{
return[
Action::make('cancel')
->label(__('filament-panels::resources/pages/edit-record.form.actions.cancel.label'))
->alpineClickHandler('document.referrer ? window.history.back() : (window.location.href = ' . Js::from($this->previousUrl ?? static::getResource()::getUrl()) . ')')
->color('gray'),
Action::make('save')
->label('save')
->submit('save')
->keyBindings(['mod+s'])
];
}
protected function getFormActions(): array
{
return[
Action::make('cancel')
->label(__('filament-panels::resources/pages/edit-record.form.actions.cancel.label'))
->alpineClickHandler('document.referrer ? window.history.back() : (window.location.href = ' . Js::from($this->previousUrl ?? static::getResource()::getUrl()) . ')')
->color('gray'),
Action::make('save')
->label('save')
->submit('save')
->keyBindings(['mod+s'])
];
}
mile4841
mile4841OP5mo ago
This solution works for me. Thank you all And you @toeknee thanks Does anyone knows how i can reorder the buttons on the modal
toeknee
toeknee5mo ago
What is it you want to do? exactly? You can clone the default action buttons and add them in
mile4841
mile4841OP5mo ago
To swap these button the button create must be last, cancel button first mine code is
Select::make('tag_id')
->required()
->preload(true)
->relationship('tags', 'title')
->label('Tags')
->searchable()
->multiple()
->createOptionForm([
TextInput::make('title')
->unique()
->required()
->maxLength(255)

])->createOptionAction(function(Action $action){
$action->mutateFormDataUsing(function(array $data){
$data['slug'] = $data['title'];
return $data;
});
}),
Select::make('tag_id')
->required()
->preload(true)
->relationship('tags', 'title')
->label('Tags')
->searchable()
->multiple()
->createOptionForm([
TextInput::make('title')
->unique()
->required()
->maxLength(255)

])->createOptionAction(function(Action $action){
$action->mutateFormDataUsing(function(array $data){
$data['slug'] = $data['title'];
return $data;
});
}),
No description
toeknee
toeknee5mo ago
Ahh on a selection I am not sure, but in an edit page etc you would tend to use: protected function getFormActions(): array { return array_reverse(parent::getFormActions()); }
Want results from more Discord servers?
Add your server