FilamentF
Filament3y ago
Homd

Dynamically Hidden Repeater Is Not Working

I have a repeater which visibility is dependent to another select field.


 return $form
            ->columns(3)
            ->schema([
Forms\Components\Select::make('unit_id')->label("Unit") ->options(fn ($livewire) => Exercise::where('id', $livewire->ownerRecord->id)->pluck("name","id")) ->default(fn ($livewire) => Exercise::find($livewire->ownerRecord->id)->id)
                ->disabled(true)
                ->required(),
Forms\Components\TextInput::make('score')->label("Score")->required()

                ->disabled(false),
Forms\Components\Select::make('exercise_type_id')->label("Question Type")
                    ->relationship('exerciseType', 'name')
                    ->default(1)
                    ->required(),
                Forms\Components\RichEditor::make("question")->columnSpan(3)->required(),                
            Repeater::make('answerlist')
            ->defaultItems(4)
            ->relationship('multipleChoiceAnswers')
            ->label("Multiple Choice Answer Option")
                ->grid(2)
            
            ->schema([
                Forms\Components\TextInput::make('text')->label("Text Answer"),
                Forms\Components\FileUpload::make('img')->label("Image Answer")
                ->directory('module-images')
                ->storeFileNamesIn("original_filename"),
                Forms\Components\Checkbox::make('is_correct_option')->label("Mark Answer As Correct")->default(false),


            ])->columnSpan(3)->required()->hidden(fn(Callable $get) => ($get('exercise_type_id') !== 1)),
            ]);


This is the specific code
->hidden(fn(Callable $get) => ($get('exercise_type_id') !== 1)),
            ]);


This is my select field

Forms\Components\Select::make('exercise_type_id')->label("Question Type")
->relationship('exerciseType', 'name')
                    ->default(1)
                    ->required(),


I've tried using
closure
instead of
callable
Solution
i don't see live()
Was this page helpful?