Advanced - Form Builder

Could you please help me understand why selecting a company name in my app results in a blank page when I use the reactive() and afterStateUpdated() methods? Your insights would be greatly appreciated. There is no error in my browser console.
Forms\Components\Select::make('company_id')
->options(\App\Models\Company::all()->pluck('name', 'id'))
->searchable()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('location_id', null))

Forms\Components\Select::make('location_id')
->label('Location')
->options(function (callable $get) {
$company = \App\Models\Company::find($get('company_id'));
if (! $company) {
return \App\Models\Location::all()->pluck('name', 'id');
}

return $company->locations->pluck('name', 'id');
})
->string()
->searchable()
->required(),
Forms\Components\Select::make('company_id')
->options(\App\Models\Company::all()->pluck('name', 'id'))
->searchable()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('location_id', null))

Forms\Components\Select::make('location_id')
->label('Location')
->options(function (callable $get) {
$company = \App\Models\Company::find($get('company_id'));
if (! $company) {
return \App\Models\Location::all()->pluck('name', 'id');
}

return $company->locations->pluck('name', 'id');
})
->string()
->searchable()
->required(),
I noticed that this occurred after upgrading to Filament v3 on a different branch.
11 Replies
bwurtz999
bwurtz99917mo ago
I think this might be the issue: $company = \App\Models\Company::find($get('company_id')); I'm not sure you can use $get in that context Do you have any logging errors you could share?
Shaung Bhone
Shaung BhoneOP17mo ago
No, I didn't get any log error Need help!
Andrew Wallo
Andrew Wallo17mo ago
Is this in a Resource or a Livewire class/form?
Shaung Bhone
Shaung BhoneOP17mo ago
Livewire form
Andrew Wallo
Andrew Wallo17mo ago
Yeah I’ve had that happen specifically only in a Livewire form. If it is an edit page, try and make sure you are filling in all the attributes in mount like “$this->form->fill([‘post’ => … ])”. Sorry for bad formatting I’m on my phone. Oh also remove the searchable on the Select, that has caused it for me before…
Shaung Bhone
Shaung BhoneOP17mo ago
It's not working
toeknee
toeknee17mo ago
->options(function (callable $get) { $company = \App\Models\Company::find($get('company_id')); if (! $company) { return \App\Models\Location::all()->pluck('name', 'id'); } return $company->locations->pluck('name', 'id'); }) ->string() Why have to passed ->string() into select list which is an array? Then provide a full page code snippet so we can see what you are doing and if you have mount etc.
Shaung Bhone
Shaung BhoneOP17mo ago
Why have to passed ->string() into select list which is an array?
I forgot to remove it. @toeknee_iom here https://gist.github.com/ShaungBhone/6962b73ef09efc4d4de7c4401c8341a7
toeknee
toeknee17mo ago
Looks generally good. Check your browser console
Shaung Bhone
Shaung BhoneOP17mo ago
There is no error in my console as I mentioned. This code is reference from Dan. https://www.youtube.com/watch?v=W_eNyimRi3w&t=2s It had worked before I updated to v3.
Shaung Bhone
Shaung BhoneOP17mo ago
Want results from more Discord servers?
Add your server