Repeater remove selected option in a select

I want to create a select inside a repeater like in the image but I want a behaviour that when I select an option in one select that option will be hidden in the others selects, can I archive it using a repeater?
4 Replies
bwurtz999
bwurtz99916mo ago
Yes, this is possible if you use
->options(function (callable $get){
$repeater = $get('../members');
})
->options(function (callable $get){
$repeater = $get('../members');
})
That $repeater variable should contain all of the information and then you can use a foreach to run through each one and remove options you don't want to appear so you'll have to return a custom array there might be a simpler way but I know this worked for me
Yeraldi29#2900
Yeraldi29#2900OP16mo ago
Thank you very much Sorry again, I haven't archived this behaviour yet, it does not affect the others selects inside the repeater I have this Repeater::make('one') ->label('') ->schema([ Select::make('code_account') ->label('Código cliente') ->options(function (ServiceAccount $record, callable $get, $state) { $repeater = $get('code_account'); $array = AccountPending::all()->pluck('user_id', 'id')->all(); $selectedOptions = [$repeater]; // Replace with the selected options from the other selects foreach ($selectedOptions as $selectedOption) { if (($key = array_search($selectedOption, $array)) !== false) { unset($array[$key]); } } return $array; }) ->reactive()
bwurtz999
bwurtz99916mo ago
@yeraldi29 you need to use $repeater = $get('../one') I think it should look like this:
->options(function (ServiceAccount $record, callable $get, $state) {

$repeater = $get('../one');

$idsToSkip = [];

foreach ($repeater as $info) {
if(isset($info['code_account'])) {
$idsToSkip[] = $info['code_account'];
}
}

$array = AccountPending::whereNotIn('id', $idsToSkip)->pluck('user_id', 'id')->toArray();

return $array;

})
->options(function (ServiceAccount $record, callable $get, $state) {

$repeater = $get('../one');

$idsToSkip = [];

foreach ($repeater as $info) {
if(isset($info['code_account'])) {
$idsToSkip[] = $info['code_account'];
}
}

$array = AccountPending::whereNotIn('id', $idsToSkip)->pluck('user_id', 'id')->toArray();

return $array;

})
Hemanath
Hemanath16mo ago
hii guys i also looking for that and i tried , but it still showing here is the code: ->options(function (callable $get) { $misc = FranchiseeMiscItemPrice::where('material_group_id', 42)->pluck('material_id'); $repeater = $get('../details.items'); $idsToSkip = []; if (is_array($repeater) || is_object($repeater)) { foreach ($repeater as $info) { if (isset($info['material_id'])) { $idsToSkip[] = $info['material_id']; } } } $material = Material::whereIn('id', $misc)->whereNotIn('id', $idsToSkip)->pluck('name', 'id'); return $material; })
Want results from more Discord servers?
Add your server