Problem Dehydrated Multiple Select

I have created a form widget with two Select fields:
Select::make('teams')
->multiple()
->relationship('teams', 'name')
->preload()
->dehydrated()
->label(__('user.fields.teams')),
Select::make('roles')
->relationship('roles', 'name')
->label(__('user.fields.roles'))
->preload()
// ->multiple()
->dehydrated(true),
// ->searchable(),
Select::make('teams')
->multiple()
->relationship('teams', 'name')
->preload()
->dehydrated()
->label(__('user.fields.teams')),
Select::make('roles')
->relationship('roles', 'name')
->label(__('user.fields.roles'))
->preload()
// ->multiple()
->dehydrated(true),
// ->searchable(),
Here is the corresponding submit function:
public function submit(): void
{
$data = $this->form->getState();
dd($data);
$data = $this->mutateFormDataBeforeCreate($data);
$this->record = $this->handleRecordCreation($data);
$this->form->model($this->getRecord())->saveRelationships();
$this->dispatch('refreshListUsers');
$this->getCreatedNotification()?->send();
}
public function submit(): void
{
$data = $this->form->getState();
dd($data);
$data = $this->mutateFormDataBeforeCreate($data);
$this->record = $this->handleRecordCreation($data);
$this->form->model($this->getRecord())->saveRelationships();
$this->dispatch('refreshListUsers');
$this->getCreatedNotification()?->send();
}
The issue is that the roles select field retrieves the data correctly, but the teams select field doesn't work as expected. Has anyone encountered this problem or found a solution?
No description
Solution:
the solution is to put in the mount() function "$this->form->fill([]);"
Jump to solution
6 Replies
toeknee
toeknee2mo ago
Fairly sure usually relationships are returned empty / bool. try ->getRawState() for the teams and the roles. But be careful since that's raw
Becker Maxime
Becker MaximeOP2mo ago
they only suck when I set the select to multiple
Becker Maxime
Becker MaximeOP2mo ago
Here's my component, I don't understand why without multiple I have the data but with multiple I don't.
David
David2mo ago
Same problem, with ->multiple in select, no data, only if use mutateFormDataBeforeCreate
Becker Maxime
Becker MaximeOP2mo ago
even using mutateFormDataBeforeCreate, I still have the problem
Solution
Becker Maxime
Becker Maxime2mo ago
the solution is to put in the mount() function "$this->form->fill([]);"
Want results from more Discord servers?
Add your server