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.07k stars 2.83k forks source link

Not working the advanced disabled option #8782

Closed gergo85 closed 12 months ago

gergo85 commented 1 year ago

Package

filament/forms

Package Version

v3.0.62

Laravel Version

10.25.1

Livewire Version

No response

PHP Version

8.2.4

Problem description

To create an interactive form, one select field should affect another. I use advanced disable option, but nothing happened.

Expected behavior

The field is not disabled.

Steps to reproduce

I use this example code: ->disabled(fn (Get $get) => $get('print_all') == 1)

Reproduction repository

https://github.com/gergo85/filament-test-selectfield

Relevant log output

No response

zepfietje commented 1 year ago

Please read the docs: https://filamentphp.com/docs/3.x/forms/getting-started#dependant-fields.

Your first field should be live().

gergo85 commented 1 year ago

I used live() but no change.

zepfietje commented 1 year ago

With or without native(false) on the second field? Because the non-native select field doesn't support dynamically disabling it due to a limitation with Choices.js.

gergo85 commented 1 year ago

Thanks for the quick response. Unfortunately, it doesn't work in either case.

ilpav12 commented 1 year ago

@gergo85 with both select native it works but not on the first load because ->default() doesn't seem to change the value of the select. It looks like even if you have have ->default(1) on the first select, on the first load $get('print_all') is null. If you change the value to 'No' and back to 'Yes' it correctly disable the second select. A possible workaround is to ->disabled() to check when $get('print_all') is null or 1. Another is to remove both ->selectablePlaceholder(false) and ->default(1) to leave the user choose an option on the first select and trigger the disabling of the second.

ilpav12 commented 1 year ago

I just saw the other issue, so I would say it is related to #8776.

zepfietje commented 12 months ago

Thanks, @ilpav12. Closing as dupe.