Closure ->visible(Get $get) in a form inside a repeater always returns the value of the first row.
I have a form in the repeater (with a relationship). In this form, I have a select field and a "reason" text field that should only be visible if the select value is "Other."
Repeater::make('dailySession')
->relationship()
->schema([
Select::make('type')->options(DailySessionTypeEnum::class)->live(),
InputText::make('reason')->visible(fn(Get $get) => $get('type')?->value === DailySessionTypeEnum::OTHER),
])
When I insert more than one record (row) into the repeater, $get('type') only returns the value of the component in the first row. So I can't conditionally display the field... I've tried several alternatives, but in my opinion, this is a bug. It doesn't make sense, and I couldn't find anything about it...
This happens with ->visible, ->hidden, ->disable...3 Replies
weird
php artisan filament:about
what is the output?
Does it work?
Hi @leandrocfe, thanks for reply!!
It was my mistake...
I tested it the way you did and it worked. Then I checked why it didn't work with the Enum and realized I forgot to compare it with the Enum's "value"...
So the correct way is:
->visible(fn(Get $get) => $get('end_type')?->value === DailySessionTypeEnum::OTHER->value)
And not
->visible(fn(Get $get) => $get('end_type')?->value === DailySessionTypeEnum::OTHER)
However, there was something that confused me about this. I tried using dd( $get('end_type')?->value) to get the incoming value, and for some reason it always came back with the value of the first record (row). So I thought that was the error...
Once again, thank you very much for your attention!! Vc é 10!!yep,
dd() will always display the first value in the loop..