Select not "registering" choice, error saying it's required
Hi! I have made a livewire component that's returning a filament form! It's a Select that gets data from the database and fills it as its options.
When I select an option and press submit, it insists that I must choose an option (even though I has chosen one).
Here is its code.
When I select an option and press submit, it insists that I must choose an option (even though I has chosen one).
Here is its code.
public function checkInAction(): Action
{
Log::info('submitAction running');
return Action::make('checkInAction')
->label('')
->color('success')
->icon('tabler-check')
->button()
->size('lg')
->extraAttributes([
'class' => 'col-span-3',
])
->form([
Forms\Components\Select::make('schedule')
->required()
->afterStateUpdated(function (?string $state, ?string $old) {
ddd('here');
})
->options(function (): array {
// Query the database for the list of schedules
// I removed this part due to the discord char limit
// It returns an array with the proper data to fill the options
// It works and shows it on the front-end
}),
])
->action(function ($data){
ddd($data);
Attendance::create(
[
'member_id' => $this->code,
'activity_id' => $data['schedule'],
'trainer_id' => 1,
'room_id' => 1,
'day' => now()->format('N'),
'start_time' => now()->format('H:i:s'),
'end_time' => now()->addHour()->format('H:i:s'),
]
);
});
}public function checkInAction(): Action
{
Log::info('submitAction running');
return Action::make('checkInAction')
->label('')
->color('success')
->icon('tabler-check')
->button()
->size('lg')
->extraAttributes([
'class' => 'col-span-3',
])
->form([
Forms\Components\Select::make('schedule')
->required()
->afterStateUpdated(function (?string $state, ?string $old) {
ddd('here');
})
->options(function (): array {
// Query the database for the list of schedules
// I removed this part due to the discord char limit
// It returns an array with the proper data to fill the options
// It works and shows it on the front-end
}),
])
->action(function ($data){
ddd($data);
Attendance::create(
[
'member_id' => $this->code,
'activity_id' => $data['schedule'],
'trainer_id' => 1,
'room_id' => 1,
'day' => now()->format('N'),
'start_time' => now()->format('H:i:s'),
'end_time' => now()->addHour()->format('H:i:s'),
]
);
});
}
Solution
Switching the component from a Select to a CheckboxList seems to have fixed the problem
