F
Filamentβ€’2mo 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
LeandroFerreiraβ€’2mo ago
console errors?
Noor
Noorβ€’2mo ago
No description
LeandroFerreira
LeandroFerreiraβ€’2mo 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
Noorβ€’2mo ago
yeah custom page , no did not added form->fill()
LeandroFerreira
LeandroFerreiraβ€’2mo 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
Noorβ€’2mo 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
LeandroFerreiraβ€’2mo 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
Noorβ€’2mo ago
nope I'm trying - this time it did not showed any console error
LeandroFerreira
LeandroFerreiraβ€’2mo ago
share the whole code you are trying
Noor
Noorβ€’2mo 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
LeandroFerreiraβ€’2mo 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
Noorβ€’2mo ago
worked Thankyou πŸ™‚
Want results from more Discord servers?
Add your server
More Posts