F
Filament4mo ago
morty

Select multiple preloaded options are reordered after selecting the input

I have a select multiple that is formFilled with options already attached on a BelongsToMany relationship. As you can see in the attached gif, the options are visible when the form is shown, but when you click the select input the options are rearranged alphabetically. Is there a way to prevent this or to load the options in already sorted so it doesn't jump on the user? My code:
Tables\Actions\Action::make('manageCollections')
->label('Manage collections')
->icon('heroicon-o-rectangle-stack')
->modalIcon('heroicon-o-rectangle-stack')
->modalWidth(MaxWidth::Small)
->fillForm(fn (Account $account) => $account->collections()->mine()->get()->all())
->form([
Forms\Components\Select::make('collections')
->label('Collections')
->multiple()
->relationship(
'collections',
'name',
fn (Builder $query) => $query->mine())->preload(),
])
->after(
fn () => Notification::make()
->success()
->title('Saved successfully')
->body('Changes to the account have been saved.')
->send()
),
Tables\Actions\Action::make('manageCollections')
->label('Manage collections')
->icon('heroicon-o-rectangle-stack')
->modalIcon('heroicon-o-rectangle-stack')
->modalWidth(MaxWidth::Small)
->fillForm(fn (Account $account) => $account->collections()->mine()->get()->all())
->form([
Forms\Components\Select::make('collections')
->label('Collections')
->multiple()
->relationship(
'collections',
'name',
fn (Builder $query) => $query->mine())->preload(),
])
->after(
fn () => Notification::make()
->success()
->title('Saved successfully')
->body('Changes to the account have been saved.')
->send()
),
I've also tried adding ->orderBy('name') to the formFill query without success. Any ideas?
2 Replies
morty
morty4mo ago
No description
morty
morty4mo ago
bump