F
Filamentβ€’4mo ago
Kaaiman

SelectFilter default not working

I am trying to set a default value on my SelectFilter:
SelectFilter::make('status')
->multiple()
->options(RefundStatus::class)
->default(RefundStatus::Pending),
SelectFilter::make('status')
->multiple()
->options(RefundStatus::class)
->default(RefundStatus::Pending),
This is about the same as in the docs, instead the docs use a string value.
Solution:
Make sure you use RefundStatus::Pending->value.
Jump to solution
4 Replies
toeknee
toekneeβ€’4mo ago
You are using multiple so:
SelectFilter::make('status')
->multiple()
->options(RefundStatus::class)
->default([RefundStatus::Pending]),
SelectFilter::make('status')
->multiple()
->options(RefundStatus::class)
->default([RefundStatus::Pending]),
Since it is an array, as I suspect your Pending isn't an array πŸ˜‰
Solution
CodeWithDennis
CodeWithDennisβ€’4mo ago
Make sure you use RefundStatus::Pending->value.
Kaaiman
KaaimanOPβ€’4mo ago
@CodeWithDennis That indeed does the trick. I must say that the filament docs are sometimes not that clear in what is possible and what's not. Be thank you for your suggestion! πŸ˜„
CodeWithDennis
CodeWithDennisβ€’4mo ago
Well because you use multiple it expects an array of values. ^ So like @toeknee said you should use an array, but since you also use an enum you need to grab the value of that enum.

Did you find this page helpful?