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
BlackpigOP6mo ago
The rendered check box list
No description
Solution
dissto
dissto6mo ago
Im not sure that ->helperText() accepts an action by default. But maybe you could use ->hintAction() instead? 🤔
Blackpig
BlackpigOP6mo ago
RTFM - I didn't know that method existed. Thanks.
Want results from more Discord servers?
Add your server