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
ChesterS12mo 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 B.V.
Proculair B.V.OP12mo 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
ChesterS12mo ago
can you try putting the ->options after ->relationship ?
Proculair B.V.
Proculair B.V.OP12mo ago
I tried that, the order does not have a different effect
Solution
ChesterS
ChesterS12mo 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 B.V.
Proculair B.V.OP12mo 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 B.V.
Proculair B.V.OP12mo ago
Thank you for looking in to this
Want results from more Discord servers?
Add your server