F
Filament14mo ago
triad

$set in afterStateUpdated () not working in v3 but worked in v2

I have the two fields below. I'm trying to update property_id when customer_id changes. This worked in v2 but doesn't work in v3. afterStateUpdated is definitely being called and I can $set other fields. Any ideas?
Select::make('customer_id')
->relationship(
'customer',
'name',
modifyQueryUsing: fn (Builder $query) => $query->whereBelongsTo(Filament::getTenant()))
->searchable()
->afterStateUpdated(function (Set $set, ?string $state) {
$set('property_id', Customer::find($state)?->properties()->first()?->id);
})
->required()
->reactive(),
Select::make('property_id')
->relationship('property', 'address_formatted',
function (Builder $query, Get $get) {
return $query->where('customer_id', $get('customer_id'));
}
)
->required(),
Select::make('customer_id')
->relationship(
'customer',
'name',
modifyQueryUsing: fn (Builder $query) => $query->whereBelongsTo(Filament::getTenant()))
->searchable()
->afterStateUpdated(function (Set $set, ?string $state) {
$set('property_id', Customer::find($state)?->properties()->first()?->id);
})
->required()
->reactive(),
Select::make('property_id')
->relationship('property', 'address_formatted',
function (Builder $query, Get $get) {
return $query->where('customer_id', $get('customer_id'));
}
)
->required(),
18 Replies
triad
triad14mo ago
@Dan Harrin any idea on this? I’ve been sponsoring you on GitHub for over a year and would appreciate any help
Dan Harrin
Dan Harrin14mo ago
hi judging by the code, its fine and nothing has changed what is the result of Customer::find($state)?->properties()->first()?->id
hdaklue
hdaklue14mo ago
Maybe it's a statePath issue
Dan Harrin
Dan Harrin14mo ago
are the relationship options being scoped by customer correctly if they are siblings, no but yeah, if this is in a repeater you might be right
hdaklue
hdaklue14mo ago
@smashville are you sure they are on the same component level?
triad
triad14mo ago
This returns the correct id
Dan Harrin
Dan Harrin14mo ago
what is the wider context are these fields really directly next to each other in the form
triad
triad14mo ago
Yes and I removed the scope to test and it still didn’t work Yes
Dan Harrin
Dan Harrin14mo ago
please open an issue with a simple reproduction repository
hdaklue
hdaklue14mo ago
did you try to change Reactive to ->live() for some reason that helped me sometimes
triad
triad14mo ago
No let me try that now
hdaklue
hdaklue14mo ago
also ->live(true) helped
triad
triad14mo ago
->live() and ->live()true didn't work ok i figured something out. thought i tested this before but apparently not. if i remove the customer_id where clause from the property_id it works. so it's trying to set before the property select updates with new relationship options
Dan Harrin
Dan Harrin14mo ago
live() === reactive() live is just the new version that stays in line with livewire 3
triad
triad14mo ago
GitHub
$set in afterStateUpdated on select with scoped relationship not wo...
Package filament/filament Package Version 3.0.42 Laravel Version 10.22.0 Livewire Version No response PHP Version 8.2.9 Problem description I'm trying to set the property select to the customer...
triad
triad14mo ago
the bot closed it automatically because i only put "see reproduction repo" in steps to reproduce
Dan Harrin
Dan Harrin14mo ago
please just write what file to look in etc what url to visit
triad
triad14mo ago
GitHub
$set in afterStateUpdated on select with scoped relationship not wo...
Package filament/filament Package Version 3.0.42 Laravel Version 10.22.0 Livewire Version No response PHP Version 8.2.9 Problem description I'm trying to set the property select to the customer...
Want results from more Discord servers?
Add your server