© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
H.Bilbao

How to update field when is hidden

Hello, I have 2 select in a form. The second is only visible when a value of the first select has a understated. I'm having trouble when I update a status that includes a substate and change it to one that doesn't, the substate is not nulled on save in the database.

Forms\Components\Select::make('status_id')
    ->relationship('status', 'name', fn(Builder $query) => $query
        ->where('parent_id', 0)
        ->orderBy('order'))
    ->required()
    ->reactive()
    ->afterStateUpdated(fn ($set) => $set('understated_id', null))
    ->default(1)
    ->disabled(isCustomer()),

Forms\Components\Select::make('understated_id')
    ->options(function (\Closure $get) {
        $status = Status::query()->where('parent_id', '=', $get('status_id'))
            ->orderBy('order')->get();
        if ($status) {
            return $status->where('parent_id', $get('status_id'))->pluck('name', 'id');
        }
        return [];
    })
    ->visible(function (\Closure $get) {
        if ($get('status_id') <> '' && Status::query()->where('parent_id', '=', $get('status_id'))->exists()) {
            return true;
        }
        return false;
    })
    ->required(),
Forms\Components\Select::make('status_id')
    ->relationship('status', 'name', fn(Builder $query) => $query
        ->where('parent_id', 0)
        ->orderBy('order'))
    ->required()
    ->reactive()
    ->afterStateUpdated(fn ($set) => $set('understated_id', null))
    ->default(1)
    ->disabled(isCustomer()),

Forms\Components\Select::make('understated_id')
    ->options(function (\Closure $get) {
        $status = Status::query()->where('parent_id', '=', $get('status_id'))
            ->orderBy('order')->get();
        if ($status) {
            return $status->where('parent_id', $get('status_id'))->pluck('name', 'id');
        }
        return [];
    })
    ->visible(function (\Closure $get) {
        if ($get('status_id') <> '' && Status::query()->where('parent_id', '=', $get('status_id'))->exists()) {
            return true;
        }
        return false;
    })
    ->required(),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Remove value when form field is hidden
FilamentFFilament / ❓┊help
3y ago
How to make secure hidden field?
FilamentFFilament / ❓┊help
2y ago
hidden and hiddenOn issue on TextColumn field.
FilamentFFilament / ❓┊help
3mo ago
Field is hidden test - Pest
FilamentFFilament / ❓┊help
11mo ago