filament icon indicating copy to clipboard operation
filament copied to clipboard

Disabled field fails validation in CheckboxList

Open JoelChoy0 opened this issue 1 month ago • 7 comments

Package

filament/filament

Package Version

v4.x.x

Laravel Version

v12.38.1

Livewire Version

v3.6.4

PHP Version

PHP 8.4.6

Problem description

When using disableOptionWhen() on a CheckboxList, validation fails for disabled options even though they are checked and submitted with the form.

The issue occurs because the validation only checks against enabled options, excluding any disabled ones. This causes the validation to reject values from disabled checkboxes that are legitimately selected and submitted.

Solution in my proyect

add ->in(fn (CheckboxList $component): array => array_keys($component->getOptions()))

Expected behavior

The documentation or examples should clarify that when validating a CheckboxList with disabled options, getOptions() should be used instead of getEnabledOptions() in the ->in() validation rule.

Steps to reproduce

  1. Create a CheckboxList form field with multiple options
  2. Use disableOptionWhen() to disable at least one option that will be checked
  3. Submit the form with the disabled option checked
  4. Observe that validation fails with the message: The form_items field is not in the list of allowed values.

use Filament\Forms\Components\CheckboxList;

CheckboxList::make('form_items') ->options([ 'name' => 'Name', 'email' => 'Email', 'phone' => 'Phone', ]) ->disableOptionWhen(fn (string $value): bool => $value === 'email');

Reproduction repository (issue will be closed if this is not valid)

https://github.com/liberty-technologies/managed-wifi

Relevant log output


JoelChoy0 avatar Nov 15 '25 18:11 JoelChoy0

Please make the reproduction repo public, and I will reopen this if you @ me

danharrin avatar Nov 16 '25 17:11 danharrin

@danharrin Hi, I created a small Laravel project so you can see what I’m referring to. This is the public link:

https://github.com/JoelChoy0/Checklist-filament

JoelChoy0 avatar Nov 17 '25 14:11 JoelChoy0

May I?

giacomomasseron avatar Nov 22 '25 11:11 giacomomasseron

Yes, no need to ask when it is marked as Bug, especially help wanted :)

danharrin avatar Nov 22 '25 11:11 danharrin

@danharrin this is a bug but I'm not sure it's the same @JoelChoy0 mentioned: if a checkbox is disabled (checked), I do not think it must be submitted. The package works as supposed to.

What happens here, it's the validation fails even if I check an enable checkbox, and I will try to fix that.

What you think?

giacomomasseron avatar Nov 23 '25 07:11 giacomomasseron

I am sorry @giacomomasseron I do not understand what you meant there

danharrin avatar Nov 23 '25 08:11 danharrin

This form fails validation:

CheckboxList::make('form_items')
    ->options([
        'name' => 'Name',
        'email' => 'Email',
        'phone' => 'Phone',
    ])
    ->default(['email'])
    ->columns()
    ->disableOptionWhen(fn (string $value): bool => $value === 'email')

I think it shouldn't fail, because there are no validation rules.

If I use this:

CheckboxList::make('form_items')
    ->options([
        'name' => 'Name',
        'email' => 'Email',
        'phone' => 'Phone',
    ])
    ->default(['email'])
    ->columns()
    ->in(fn (CheckboxList $component): array => array_keys($component->getEnabledOptions())) // Added validation rule
    ->disableOptionWhen(fn (string $value): bool => $value === 'email')

the form fails even if I check an enabled checkbox (and I think this is the bug mentioned).

giacomomasseron avatar Nov 23 '25 08:11 giacomomasseron