FilamentF
Filament15mo 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)
}),

As:
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:
->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([])
}),
Was this page helpful?