filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.09k stars 2.83k forks source link

Select field disabled() broken behaviour when native(false) is set #10263

Closed diogogpinto closed 9 months ago

diogogpinto commented 9 months ago

Package

filament/filament

Package Version

v3.1.19

Laravel Version

v10.34.2

Livewire Version

No response

PHP Version

PHP 8.2.9

Problem description

Imagine two select fields, the second one being related to the first:

Select field A

  • Option A
  • Option B

Select Field B

  • If (Select field A = Option A) -- Option C -- Option D
  • If (Select field A = Option B) -- NULL

If the second one doesn't have options inherited from the first one, it should be disabled. But,. when it inherits the options it should show a list of options.

This works fine with native(true), but not when using native(false).

Expected behavior

It should display a dropdown select with the inherited options or it should be disabled.

Steps to reproduce

In any resource, add the following form schema:

Forms\Components\Select::make('selectOne')
    ->label('Enable or disable second select?')
    ->options(
        [
            'disable' => 'Disable',
            'enable' => 'Enable'
        ]
    )
    ->live()
    ->afterStateUpdated(function (Forms\Set $set) {
        $set('selectTwo', NULL);
    })
    ->required()
    ->native(false),

Forms\Components\Select::make('selectTwo')
    ->label('Is this enabled or disabled?')
    ->live()
    ->options(fn (Forms\Get $get): array => match ($get('selectOne')) {
        'enable' => ['Option 1', 'Option 2', 'Option 3'],
        'disable' => [],
        default => [],
    })
    ->disabled(fn (Forms\Components\Component $component) => empty($component->getOptions()))
    ->native(false),

Reproduction repository

https://github.com/filamentphp/demo

Relevant log output

No response

danharrin commented 9 months ago

Duplicate of #3068.