Why select multiple is always searchable?

in my users table i have set this select for when i create a new user (modal):
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->searchable(false)
,
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->searchable(false)
,
im trying to set - ->searchable(false), but it is always searchable anyways. how to disable the search in a select multiple???
Solution:
final code: ```php Select::make('roles') ->multiple() ->relationship('roles', 'name')...
Jump to solution
14 Replies
Dennis Koch
Dennis Koch16mo ago
I don't think it's possible since we use ChoicesJS for multiselect which comes with a search.
ericmp #2
ericmp #2OP16mo ago
in v3 is different, right? this can be done
Dennis Koch
Dennis Koch16mo ago
I don't think there is any difference. We still use ChoicesJS
ericmp #2
ericmp #2OP16mo ago
fak, okay 🤔 the thing is that id like to remove the search, cuz when i search the options change i have them translated but then, as user search, i see them untranslated - https://discord.com/channels/883083792112300104/1141621034731188274
Dennis Koch
Dennis Koch16mo ago
I think you should use a Callback on ->relationship() (3rd param) to limit your relationship query and use getOptionLabelFromRecord() method to format your options.
ericmp #2
ericmp #2OP16mo ago
would u mind to guide me a little bit on how to do this? wdym to limit the query? so far i did this:
...
->label(__('Roles'))
->getOptionLabelFromRecordUsing(function (Role $record) {
return __($record->name);
})
...
->label(__('Roles'))
->getOptionLabelFromRecordUsing(function (Role $record) {
return __($record->name);
})
toeknee
toeknee16mo ago
You should be able to select maxItems(1) if memory serves me right.
ericmp #2
ericmp #2OP16mo ago
how to do that? 🤔
toeknee
toeknee16mo ago
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->searchable(false)
->maxItems(1)
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->searchable(false)
->maxItems(1)
ericmp #2
ericmp #2OP16mo ago
it keeps the items translated when searching, but the search searches them by not translated i mean that if i search "jugador", i see 0 results when i should see 1 result cuz is trying to search "player" instead (player is jugador, but translated) i fixed it!
Solution
ericmp #2
ericmp #216mo ago
final code:
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->preload()
,
Select::make('roles')
->multiple()
->relationship('roles', 'name')
->options(function () {
return Role::query()
->when(! auth()->user()->hasRole('Superadmin'), function ($q) {
$q->where('name', '!=', 'Superadmin');
})
->pluck('name', 'id')
->map(function ($caseName) {
return __($caseName);
})
->toArray()
;
})
->label(__('Roles'))
->preload()
,
ericmp #2
ericmp #2OP16mo ago
so the thing is just preloading it so it searches the translated options else, searches in db, where arent translated and kinda bugs out if searching
Dennis Koch
Dennis Koch16mo ago
Ah, sorry. Didn't realize that your translations aren't stored in the DB
ericmp #2
ericmp #2OP16mo ago
its okayy, thanks y'all for ur time
Want results from more Discord servers?
Add your server