F
Filament16mo 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)),
]);
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)),
]);
->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(),
Forms\Components\Select::make('exercise_type_id')->label("Question Type")
->relationship('exerciseType', 'name')
->default(1)
->required(),
I've tried using
closure
closure
instead of
callable
callable
Solution:
i don't see live()
Jump to solution
6 Replies
krekas
krekas16mo ago
I think you need to get one level down
Homd
HomdOP16mo ago
I've dumped $get('exercise_type_id') and it's working as expected. But the value is only being updated on page load. For example if I set the default value of my select to id of 1/2/3, it will obtain that value. But after page load finished, If I change it by form, the repeater does not get updated. It just like the id checking only happening on mount() and not render() I'm so lost and feel defeated xD I've been stuck on this problem for 2 days which I think is fairly simple
Solution
krekas
krekas16mo ago
i don't see live()
Homd
HomdOP16mo ago
OMG, I don't even know I need to use live() flag. Thx!!!
krekas
krekas16mo ago
If want it to be reactive you need it It's a livewire feature

Did you find this page helpful?