Default select not being selected

I want to select fields of a select by default I do this:
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->default('draft')
->multiple()
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->default('draft')
->multiple()
And i get this:
No description
13 Replies
ericmp #2
ericmp #210mo ago
When i expected to get by default selected:
No description
toeknee
toeknee10mo ago
you allow multiple so pass it as an array: ->default(['draft']) Also, it will only work on creation not edit
ericmp #2
ericmp #210mo ago
yeah, on creating im doing it let me try as array as array doesnt work neither
toeknee
toeknee10mo ago
Is this a custom component?
ericmp #2
ericmp #210mo ago
no
toeknee
toeknee10mo ago
So you are not using a Custom Livewire component? What is this on? A Resource?
ericmp #2
ericmp #210mo ago
oh sorry, yeah im not using admin panel, is the form package
toeknee
toeknee10mo ago
Soo it is custom on the mount function make sure to include: $this->form->fill(); for creation
ericmp #2
ericmp #210mo ago
yeah im doing the fill when mounting:
$this->socialMedia = new SocialMedia();

$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
])->toArray());
$this->socialMedia = new SocialMedia();

$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
])->toArray());
i tried to add status too:
$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
'status' => null,
])->toArray());
$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
'status' => null,
])->toArray());
toeknee
toeknee10mo ago
Right so that's likely your issue. You are removing it by providing an empty array
ericmp #2
ericmp #210mo ago
but same result
toeknee
toeknee10mo ago
$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
'status' => ['draft'],
])->toArray());
$this->form->fill(collect($this->socialMedia->toArray())->merge([
'type' => SocialMediaType::Calendar->value,
'status' => ['draft'],
])->toArray());
ericmp #2
ericmp #210mo ago
yeah it works now, okay i understand, thanks! but lets say another select changes, and when it changes i want to fill the status. how would be achieved? by setting it reactive and setting its value when changes?