Hide disabledOption in Select

When disabling an option in Select I would like to not display that option. How is this possible?
Select::make(static::$name)
->label(static::$label)
->relationship(static::$name, static::$attribute)
->preload()
->multiple()
->disableOptionWhen(function (string $value, ManageCustomerUsers $livewire): bool {
return $livewire->getOwnerRecord()->id === $value;
});
Select::make(static::$name)
->label(static::$label)
->relationship(static::$name, static::$attribute)
->preload()
->multiple()
->disableOptionWhen(function (string $value, ManageCustomerUsers $livewire): bool {
return $livewire->getOwnerRecord()->id === $value;
});
Solution:
eg this works for me - it hides the current user from the list of users ```php Forms\Components\Select::make('user_id') ->relationship('user', 'name') ->options(fn() => User::whereNot('id' , auth()->id())->pluck('name', 'id')),...
Jump to solution
7 Replies
ChesterS
ChesterS6mo ago
Why not just not show it using ->options()? eg ->options(fn($record) => YourModel::whereNot('id', $record->id)->get('name', 'id') or something similar? (code just an example)
Proculair
Proculair6mo ago
Yeah that should work, lemme check if that does not interfere with the relationship I've checked and the ->relationship() parts overwrites the ->options() part
ChesterS
ChesterS6mo ago
can you try putting the ->options after ->relationship ?
Proculair
Proculair6mo ago
I tried that, the order does not have a different effect
Solution
ChesterS
ChesterS6mo ago
eg this works for me - it hides the current user from the list of users
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->options(fn() => User::whereNot('id' , auth()->id())->pluck('name', 'id')),
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->options(fn() => User::whereNot('id' , auth()->id())->pluck('name', 'id')),
Proculair
Proculair6mo ago
Oh man my bad, I was currently working on a problem with SelectFilter and did not register that this problem was about Select I will try this once more but than on the correct eleement --- Yes that works!
Proculair
Proculair6mo ago
Thank you for looking in to this
Want results from more Discord servers?
Add your server
More Posts