ashtrath
ashtrath
FFilament
Created by ashtrath on 2/5/2025 in #❓┊help
Issue with Fieldset Visibility on Form Edit first render
Context: I'm working with Filament forms and have a fieldset (Student Information) that should only be visible when the role field is set to 4. The role is set via a Select field where I assign a role ID. The Problem: - When editing a user with an existing role ID (e.g., 4), the Student Information fieldset doesn't appear on first render until I change the role and then set it back to 4. - I expect the fieldset to be visible as soon as the form is rendered if the user’s role id is already 4, but it remains hidden until the role is selected again. Code Example:
<?php

namespace App\Filament\Resources\UserResource\Forms;

use App\Models\Student;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Illuminate\Database\Eloquent\Builder;

class UserForm
{
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\Fieldset::make('Account Information')->schema([
Forms\Components\Select::make('role')
->label('Role')
->relationship('roles', 'name', fn(Builder $query) => $query->where('name', '!=', 'Admin'))
->preload()
->live()
->searchable()
->required(),
]),
Forms\Components\Fieldset::make('Student Information')->schema([
Forms\Components\TextInput::make('nim')->required(),
Forms\Components\Select::make('gender')->required(),
])->visible(fn(Get $get) => $get('role') === '4')
]);
}
}
<?php

namespace App\Filament\Resources\UserResource\Forms;

use App\Models\Student;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Illuminate\Database\Eloquent\Builder;

class UserForm
{
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\Fieldset::make('Account Information')->schema([
Forms\Components\Select::make('role')
->label('Role')
->relationship('roles', 'name', fn(Builder $query) => $query->where('name', '!=', 'Admin'))
->preload()
->live()
->searchable()
->required(),
]),
Forms\Components\Fieldset::make('Student Information')->schema([
Forms\Components\TextInput::make('nim')->required(),
Forms\Components\Select::make('gender')->required(),
])->visible(fn(Get $get) => $get('role') === '4')
]);
}
}
The Issue Details: - Expected Behavior: The Student Information fieldset should be visible as soon as the form loads if the role field is set to 4. - Actual Behavior: The fieldset is hidden on first render, and only becomes visible after I change the role and select 4 again.
6 replies