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
Yes, this is possible
if you use
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 meThank 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()
@yeraldi29 you need to use
$repeater = $get('../one')
I think it should look like this:
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;
})