F
Filament2mo ago
nowak

How to remove createAnother button from createOptionAction modal?

In a Form Select field, when I want to add the abilitiy to create another option on the relationship, it only makes sense in some cases to add one extra option that needs to be selected by the select field. Here I do not want to see the "Create & create another" action in my modal, as this only confuses the end user. This does not work:
->createOptionAction(function (Action $action) {
return $action
->createAnother(false)
}),
->createOptionAction(function (Action $action) {
return $action
->createAnother(false)
}),
As:
Method Filament\Forms\Components\Actions\Action::createAnother does not exist.
Method Filament\Forms\Components\Actions\Action::createAnother does not exist.
How can we remove this action from the createOptionAction modal?
Solution:
Okay, so that cleared it up. in the getCreateOptionAction() method in the filament/packages/forms/src/Components/Select.php class, an extra modal footer action is added conditionally: ```php ->extraModalFooterActions(fn (Action $action, Select $component): array => $component->isMultiple() ? [ $action->makeModalSubmitAction('createAnother', arguments: ['another' => true]) ->label(__('filament-forms::components.select.actions.create_option.modal.actions.create_another.label')),...
Jump to solution
6 Replies
toeknee
toeknee2mo ago
Hmm can you provide the whole code because I am not seeing tha ton my table createAction? example:
Select::make('rank_id')
->label('Rank')
->columnSpan(3)
->relationship('crewRank', 'name')
->createOptionForm(function () {
return [
TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->placeholder('Rank Name'),
TextInput::make('description')
->placeholder('Rank Description'),
TextInput::make('order')
->hidden()
->default(10)
->placeholder('Rank Order'),
];
}),
Select::make('rank_id')
->label('Rank')
->columnSpan(3)
->relationship('crewRank', 'name')
->createOptionForm(function () {
return [
TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->placeholder('Rank Name'),
TextInput::make('description')
->placeholder('Rank Description'),
TextInput::make('order')
->hidden()
->default(10)
->placeholder('Rank Order'),
];
}),
Has no 'Create Another' option.
nowak
nowakOP2mo ago
Ahh.. It only does that when you use a ->multiple() select field. example:
Select::make('tags')
->label('Tags')
->multiple()
->relationship(
name: 'tags',
titleAttribute: 'name',
)
->createOptionForm(function () {
return [
TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->placeholder('Tag Name'),
TextInput::make('description')
->placeholder('Tag Description'),
];
}),
Select::make('tags')
->label('Tags')
->multiple()
->relationship(
name: 'tags',
titleAttribute: 'name',
)
->createOptionForm(function () {
return [
TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->placeholder('Tag Name'),
TextInput::make('description')
->placeholder('Tag Description'),
];
}),
toeknee
toeknee2mo ago
you'll need to intercept extraModalFooterActions and remove it
Solution
nowak
nowak2mo ago
Okay, so that cleared it up. in the getCreateOptionAction() method in the filament/packages/forms/src/Components/Select.php class, an extra modal footer action is added conditionally:
->extraModalFooterActions(fn (Action $action, Select $component): array => $component->isMultiple() ? [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('filament-forms::components.select.actions.create_option.modal.actions.create_another.label')),
] : []);
->extraModalFooterActions(fn (Action $action, Select $component): array => $component->isMultiple() ? [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('filament-forms::components.select.actions.create_option.modal.actions.create_another.label')),
] : []);
So this is a way to remove it:
->createOptionAction(function (Action $action) {
return $action
->extraModalFooterActions([])
}),
->createOptionAction(function (Action $action) {
return $action
->extraModalFooterActions([])
}),
toeknee
toeknee2mo ago
exactly 🙂
nowak
nowakOP2mo ago
Strange that this is forced on the modal like that, without an option to disable it here. But hey ho, this works
Want results from more Discord servers?
Add your server