Add an option to Checkboxlist via an Action

I'm trying to recreate similar behaviour to the ->createOptionForm() of the Form\Select component https://filamentphp.com/docs/3.x/forms/fields/select#creating-a-new-option-in-a-modal but on a CheckboxList. I was hoping I could utilise either the ->helpertext() or ->hint() methods and trigger an Action. It renders ok - but the Action doesn't trigger the modal/form - is this possible or do I need top change my approach?
CheckboxList::make('roles')
->helperText(function(): Action {
return Action::make('createRole')
->label('Add a new role')
->link()
->form([
TextInput::make('title')
->required(),
TextInput::make('hourly_rate')
->label('Hourly Rate')
->required()
->type('number')
->inputMode('decimal')
->default('25.00'),
])
->action(function (array $data): void {
$newRole = new StaffRole;
$newRole->title = $data['title'];
$newRole->hourly_rate = $data['hourly_rate'];
$newRole->save();
});
})
//->url(fn() => route('filament.admin.resources.staff-roles.create'))
->required()
->relationship(titleAttribute: 'title')
->columns(4)
]);
CheckboxList::make('roles')
->helperText(function(): Action {
return Action::make('createRole')
->label('Add a new role')
->link()
->form([
TextInput::make('title')
->required(),
TextInput::make('hourly_rate')
->label('Hourly Rate')
->required()
->type('number')
->inputMode('decimal')
->default('25.00'),
])
->action(function (array $data): void {
$newRole = new StaffRole;
$newRole->title = $data['title'];
$newRole->hourly_rate = $data['hourly_rate'];
$newRole->save();
});
})
//->url(fn() => route('filament.admin.resources.staff-roles.create'))
->required()
->relationship(titleAttribute: 'title')
->columns(4)
]);
Solution:
Im not sure that ->helperText() accepts an action by default. But maybe you could use ->hintAction() instead? 🤔
Jump to solution
3 Replies
Blackpig
Blackpig2w ago
The rendered check box list
No description
Solution
dissto
dissto2w ago
Im not sure that ->helperText() accepts an action by default. But maybe you could use ->hintAction() instead? 🤔
Blackpig
Blackpig2w ago
RTFM - I didn't know that method existed. Thanks.
Want results from more Discord servers?
Add your server
More Posts
Failed to disabled select before another select```Forms\Components\Select::make('from_id') ->relationship(name: 'from', Column URL - apply only to text, not the whole cell?My users are a bit thrown off that in an otherwise clickable row, the whitespace in a URL column folRichEditor content inside a repeater can't be viewed in update pageHi, in prod, i don't understand, why the content of RichEditor field, inside a repeater, can't be viWhat is the best/easiest way to overwrite a resource within a package?I'm using the following 2 packages and would like to edit both resources: ``` "z3d0x/filameExporter - include relationships as extra rowsUsing the Exporter for a table - am trying to inject additional rows for relationships that exist. THow can I display a file uploaded using the spatie media library on the info list pageHey all!, in my filament project I'm making use of of the spatie media library for filament (https:/How i can disable submit button until form is fully validated filament```Forms\Components\Select::make('from_id')->relationship(name: 'from', modifyQueryUsing: fn (BuildeCan not add table to a componentI have a custom component where i want to display a table. Implemented the trait and interface: `How i can display the error message before submit``` Forms\Components\Select::make('from_id') ->relationship(name: 'from', I used a checkbox in the filter and it has default true.Hi everyone, I used a checkbox in the filter and it has default true. but I want to disable or hide