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

Dependant select options #7737

Closed 8888post closed 1 year ago

8888post commented 1 year ago

Package

filament/filament

Package Version

v3.0.20

Laravel Version

v10.18.0

Livewire Version

v3.0.0-beta.7

PHP Version

PHP 8.2.8

Problem description

Hi I want to Implement "Dependant select options" The problem is after changing the parent category, subcategories values are not resting.

https://github.com/filamentphp/filament/assets/7103235/afbb6912-4de2-42ec-afd6-e1b23ec236b2

Expected behavior

We expected after changing the parent category, all subcategories will be reset.

Steps to reproduce


use Filament\Forms\Get;
use Filament\Forms\Components\Select;

Select::make('category')
->options([
    'web' => 'Web development',
    'mobile' => 'Mobile development',
    'design' => 'Design',
])
->live(),

Select::make('sub_category')
->options(fn (Get $get): array => match ($get('category')) {
    'web' => [
        'frontend_web' => 'Frontend development',
        'backend_web' => 'Backend development',
    ],
    'mobile' => [
        'ios_mobile' => 'iOS development',
        'android_mobile' => 'Android development',
    ],
    'design' => [
        'app_design' => 'Panel design',
        'marketing_website_design' => 'Marketing website design',
    ],
    default => [],
})
->live(),

Select::make('sub_category2')
->options(fn (Get $get): array => match ($get('sub_category')) {
    'frontend_web' => [
        'vuejs' => 'VueJs',
        'react' => 'React',
    ],
    'backend_web' => [
        'laravel' => 'Laravel',
        'net' => '.Net',
    ],
    'android_mobile' => [
        'java' => 'Java',
        'kotlin' => 'Kotlin',
    ],

    default => [],
}),

Reproduction repository

https://github.com/filamentphp/filament

Relevant log output

No response

github-actions[bot] commented 1 year ago

Hey @8888post! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.