Select component resets after save or state update

I have a simple form on custom page with select component but when I click on save button the it resets the select component (blank with no styling) and I get an error in console: Uncaught (in promise) TypeError: Expected one of the following types text|select-one|select-multiple Test.php
public User $user;

protected function getFormSchema(): array
{
return [
Card::make([
Select::make('business_model')
->options([...])
->searchable(),

Select::make('property_types')
->options([...])
->multiple()
->reactive()
])->columns()
];
}

protected function getFormModel(): Model|string|null
{
return $this->user;
}

public function save(): void
{
$this->user->update($this->form->getState());
$this->notify('success', 'Saved');
}

public function mount(): void
{
$this->user = Auth::user();
$this->form->fill($this->user->toArray());
}
}
public User $user;

protected function getFormSchema(): array
{
return [
Card::make([
Select::make('business_model')
->options([...])
->searchable(),

Select::make('property_types')
->options([...])
->multiple()
->reactive()
])->columns()
];
}

protected function getFormModel(): Model|string|null
{
return $this->user;
}

public function save(): void
{
$this->user->update($this->form->getState());
$this->notify('success', 'Saved');
}

public function mount(): void
{
$this->user = Auth::user();
$this->form->fill($this->user->toArray());
}
}
test.blade.php
<x-filament::page>
<form wire:submit.prevent="save" class="space-y-6">
{{ $this->form }}

<x-filament::button type="submit" wire:target="save">Save changes</x-filament::button>
</form>
</x-filament::page>
<x-filament::page>
<form wire:submit.prevent="save" class="space-y-6">
{{ $this->form }}

<x-filament::button type="submit" wire:target="save">Save changes</x-filament::button>
</form>
</x-filament::page>
2 Replies
Dan Harrin
Dan Harrin2y ago
because you have no livewire properties for your fields, check the docs the easiest way is to define public $data = [] and then return data from getFormStatePath()
Darpan
DarpanOP2y ago
Okay, it worked, thanks!

Did you find this page helpful?