F
Filament13mo ago
ciorici

Reuse filament select multiple in custom component

I am trying to re-use some of Filaments components, and I am looking specifically to use the Select with multiple options. I saw the code below which seems to be working fine for simple selects, but I can't get it to work with multiple values. Can someone please help? I am not that good with Livewire and Laravel, still learning this through... Thanks! <x-filament::input.wrapper> <x-filament::input.select wire:model="records"> <option value="draft">Draft</option> <option value="reviewing">Reviewing</option> <option value="published">Published</option> </x-filament::input.select> </x-filament::input.wrapper>
4 Replies
torriv
torriv13mo ago
the way i did it was making a trait.
trait YourTraitName
{
public static function yourFunctionName(): array
{
return [
Select::make('status')->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
]),
];
}
}
trait YourTraitName
{
public static function yourFunctionName(): array
{
return [
Select::make('status')->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
]),
];
}
}
then in your resource form:
use App\Traits\YourTraitName;

public static function form(Form $form): Form{
return $form->schema([
...self::yourFunctionName(),
//other fields
]);
}
use App\Traits\YourTraitName;

public static function form(Form $form): Form{
return $form->schema([
...self::yourFunctionName(),
//other fields
]);
}
toeknee
toeknee13mo ago
Are you always using it in a Filament Form?
ciorici
cioriciOP13mo ago
No, I am not using it inside a Filament Form, it's just in a custom Livewire component I am creating. Any ideas?
toeknee
toeknee13mo ago
Multiples probably requires some JS Assets. Check what happens when we include ->multiple() on the original field component
Want results from more Discord servers?
Add your server