F
Filament14mo ago
Plague

Repeater with ->distinct() Checkbox, how to not require one be selected.

The Repeater works great, I have an 'is_default' column for each item, I am using ->distinct() to make sure only 1 can be set to default. However I also want to support not selecting a default option. My issue is that if I try to save without checking one of the Repeater items as default it won't let me and shows a validation error "At least one is Default field must be selected." Here is my current the "Is Default" field in my Repeater.
Forms\Components\Checkbox::make('is_default')
->label('Is Default')
->default(false)
->distinct()
->fixIndistinctState()
->inline(false)
->columnSpan(1),
Forms\Components\Checkbox::make('is_default')
->label('Is Default')
->default(false)
->distinct()
->fixIndistinctState()
->inline(false)
->columnSpan(1),
I have tried adding ->nullable(), ->required(false), ->optional() I wan't the default checkbox to be optional, is there a way to make ->distinct() not require that one be selected?
3 Replies
Plague
PlagueOP14mo ago
I am still looking for a solution to this. Was considering not making it "distinct()" and just having a warning saying only check 1 default at most, ->distinct() is a better experience for the user though.
awcodes
awcodes14mo ago
Looking at the code, I think this would need a PR to accept an attribute for distinct(). Feel free to submit and issue or a PR that would allow it.
Adnan Yalahow
Adnan Yalahow14mo ago
Are you trying to make sure at least one checkbox is checked in your repeater

Did you find this page helpful?