F
Filament2y ago
Abi

How to show/hide fields inside a repeater with a reactive field in a repeater?

I am using the Standalone Form Builder. I have to show and hide a TextInput within a repeater based on the value selected on a Select element inside the repeater. Here is what I have
Repeater::make('items')
->label('Items')
->schema([
Select::make('item')->label('What item on this tracking number are you claiming?')->options([
'item1' => 'Item 1',
'item2' => 'Item 2',
'item3' => 'Item 3',
])->reactive(),
Radio::make('claim_type')
->label('Claim Type')
->inline()
->options([
'damage' => 'Damage',
'lost' => 'Lost',
'stolen' => 'Stolen',
])->visible(?),
Repeater::make('items')
->label('Items')
->schema([
Select::make('item')->label('What item on this tracking number are you claiming?')->options([
'item1' => 'Item 1',
'item2' => 'Item 2',
'item3' => 'Item 3',
])->reactive(),
Radio::make('claim_type')
->label('Claim Type')
->inline()
->options([
'damage' => 'Damage',
'lost' => 'Lost',
'stolen' => 'Stolen',
])->visible(?),
I am not sure what actually goes inside the visible method. I am assuming there is a way to get the current item index on the repeater and check for the value. Any advice?
13 Replies
Dennis Koch
Dennis Koch2y ago
I think it's fn ($get) => $get('./item') or just `fn ($get) => $get('item')
Abi
AbiOP2y ago
ok, let me try them. a related question, is it possible to disable the Add more Items based on the value selected inside the repeater?
Dennis Koch
Dennis Koch2y ago
Not sure sorry.
Abi
AbiOP2y ago
ok May Be Dan or awcodes may have some idea.
Patrick Boivin
->disableItemCreation(fn () => ... )
Abi
AbiOP2y ago
this one works
->addable(function ($get) {
if (blank($get('items'))) {
return true;
}

return count(Arr::where($get('items'), function ($item) {
return $item['item'] === 'WHOLE';
})) === 0;
})
->addable(function ($get) {
if (blank($get('items'))) {
return true;
}

return count(Arr::where($get('items'), function ($item) {
return $item['item'] === 'WHOLE';
})) === 0;
})
Dan Harrin
Dan Harrin2y ago
doesnt matter that its inside the repeater it works outside and inside fn ($get) => $get('item') === 'item1'
Abi
AbiOP2y ago
Thank you. BTW, I have been using v3 for a new app and its been great. at times I face some bugs, is there a place I can report them? I know its still in development, but I like living on the edge and hoping that Livewire v3 is released at Laracon
Abi
AbiOP2y ago
For Example, here is a one that I am facing. trying to figure out what is causing the issue
Abi
AbiOP2y ago
nvm, actually I get this error only when I use Octane
Dan Harrin
Dan Harrin2y ago
we do not have the time to support people who are using it when its not ready 🤷‍♂️ sorry
Abi
AbiOP2y ago
no problem, was just curious to help with the new version. Will wait for when it is released. But enjoying the alpha releases though
Dennis Koch
Dennis Koch2y ago
We are happy for feedback when we'll release a public beta and have some public documentation
Want results from more Discord servers?
Add your server