F
Filament6mo ago
Noor

multiple() is not working in form select

I have a Select::make('salesperson') on my form and its works fine If I use options but when I use multiple with it, it does not show anything in the search bar saying no results found My code
Select::make('salesperson')
->multiple()
->options($this->options)
->disablePlaceholderSelection()
->live(),
Select::make('salesperson')
->multiple()
->options($this->options)
->disablePlaceholderSelection()
->live(),
I also tested it with below code shows same issue
Select::make('salesperson')
->multiple()
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
Select::make('salesperson')
->multiple()
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
Solution:
It should be ```php public ?array $data = []; ...
Jump to solution
12 Replies
LeandroFerreira
LeandroFerreira6mo ago
console errors?
Noor
NoorOP6mo ago
No description
LeandroFerreira
LeandroFerreira6mo ago
You are using a custom page or a livewire component, right? Did you add $this->form->fill() in the mount method? Did you create a state path in your form?
Noor
NoorOP6mo ago
yeah custom page , no did not added form->fill()
LeandroFerreira
LeandroFerreira6mo ago
If you are using a custom page or a custom Livewire component, please follow these steps: - Add $this->form->fill() in the mount method.
public function mount(): void
{
$this->form->fill();
}
public function mount(): void
{
$this->form->fill();
}
- For the fields in your form, choose one of the following: - (Recommended) Create a statePath in your form.
public ?array $data = [];

public function form(Form $form): Form
{
return $form
->schema([
// ...
])
->statePath('data');
}
public ?array $data = [];

public function form(Form $form): Form
{
return $form
->schema([
// ...
])
->statePath('data');
}
- or add the field as a public property in your Livewire component.
public $field1;
public $field2;
...
public $field1;
public $field2;
...
Noor
NoorOP6mo ago
public $start;
public $end;
public $salesperson = 0;
public $options;

public function mount(): void
{
$this->start = now()->subDays(7)->format('Y-m-d h:i:s');
$this->end = now()->format('Y-m-d h:i:s');
$this->salesperson = 0;
$options = [];
$options[0] = 'All';
$salespeople = User::orderBy('created_at', 'desc')->get();
foreach($salespeople as $salesperson) {
$options[$salesperson->id] = $salesperson->name;
}
$this->options = $options;
}

public function getFormSchema(): array
{
return [
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->multiple()
->searchable()
->options($this->options)
->disablePlaceholderSelection()
->live(),
])
public $start;
public $end;
public $salesperson = 0;
public $options;

public function mount(): void
{
$this->start = now()->subDays(7)->format('Y-m-d h:i:s');
$this->end = now()->format('Y-m-d h:i:s');
$this->salesperson = 0;
$options = [];
$options[0] = 'All';
$salespeople = User::orderBy('created_at', 'desc')->get();
foreach($salespeople as $salesperson) {
$options[$salesperson->id] = $salesperson->name;
}
$this->options = $options;
}

public function getFormSchema(): array
{
return [
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->multiple()
->searchable()
->options($this->options)
->disablePlaceholderSelection()
->live(),
])
@Leandro Ferreira using this in my code
LeandroFerreira
LeandroFerreira6mo ago
you should use form fill
$this->form->fill([
'start' => xxx,
'end' => yyy,
...
]);
$this->form->fill([
'start' => xxx,
'end' => yyy,
...
]);
@Noor, did it work?
Noor
NoorOP6mo ago
nope I'm trying - this time it did not showed any console error
LeandroFerreira
LeandroFerreira6mo ago
share the whole code you are trying
Noor
NoorOP6mo ago
public $start;
public $end;
public $salesperson = 0;
public $options;
public ?array $data = [];

public function mount(): void
{
$this->form->fill([
// $this->start = now()->subDays(7)->format('Y-m-d h:i:s'),
// $this->end = now()->format('Y-m-d h:i:s'),
// $this->salesperson = 0,
'start' => now()->subDays(7)->format('Y-m-d h:i:s'),
'end' => now()->format('Y-m-d h:i:s'),
'salesperson' => 0,
]);
$options = [];
$options[0] = 'All';
$salespeople = User::orderBy('created_at', 'desc')->get();
foreach($salespeople as $salesperson) {
$options[$salesperson->id] = $salesperson->name;
}
$this->options = $options;
}

public function getFormSchema(): array
{
return [
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->multiple()
->searchable()
->options($this->options)
->disablePlaceholderSelection()
->live()
])
->statePath('data'),

];
}
public $start;
public $end;
public $salesperson = 0;
public $options;
public ?array $data = [];

public function mount(): void
{
$this->form->fill([
// $this->start = now()->subDays(7)->format('Y-m-d h:i:s'),
// $this->end = now()->format('Y-m-d h:i:s'),
// $this->salesperson = 0,
'start' => now()->subDays(7)->format('Y-m-d h:i:s'),
'end' => now()->format('Y-m-d h:i:s'),
'salesperson' => 0,
]);
$options = [];
$options[0] = 'All';
$salespeople = User::orderBy('created_at', 'desc')->get();
foreach($salespeople as $salesperson) {
$options[$salesperson->id] = $salesperson->name;
}
$this->options = $options;
}

public function getFormSchema(): array
{
return [
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->multiple()
->searchable()
->options($this->options)
->disablePlaceholderSelection()
->live()
])
->statePath('data'),

];
}
Solution
LeandroFerreira
LeandroFerreira6mo ago
It should be
public ?array $data = [];

public function mount(): void
{
$this->form->fill([
'start' => now()->subDays(7)->format('Y-m-d'),
'end' => now()->format('Y-m-d'),
'salesperson' => null,
]);
}

public function form(Form $form): Form
{
return $form
->schema([
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->options(fn () => User::orderBy('created_at', 'desc')->pluck('name', 'id'))
->multiple()
->searchable()
->selectablePlaceholder(),
]),
])
->statePath('data');
}
public ?array $data = [];

public function mount(): void
{
$this->form->fill([
'start' => now()->subDays(7)->format('Y-m-d'),
'end' => now()->format('Y-m-d'),
'salesperson' => null,
]);
}

public function form(Form $form): Form
{
return $form
->schema([
Grid::make(3)->schema([
DatePicker::make('start'),
DatePicker::make('end'),
Select::make('salesperson')
->options(fn () => User::orderBy('created_at', 'desc')->pluck('name', 'id'))
->multiple()
->searchable()
->selectablePlaceholder(),
]),
])
->statePath('data');
}
Noor
NoorOP6mo ago
worked Thankyou 🙂
Want results from more Discord servers?
Add your server