F
Filament15mo 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
triadOP15mo 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 Harrin15mo ago
hi judging by the code, its fine and nothing has changed what is the result of Customer::find($state)?->properties()->first()?->id
hdaklue
hdaklue15mo ago
Maybe it's a statePath issue
Dan Harrin
Dan Harrin15mo 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
hdaklue15mo ago
@smashville are you sure they are on the same component level?
triad
triadOP15mo ago
This returns the correct id
Dan Harrin
Dan Harrin15mo ago
what is the wider context are these fields really directly next to each other in the form
triad
triadOP15mo ago
Yes and I removed the scope to test and it still didn’t work Yes
Dan Harrin
Dan Harrin15mo ago
please open an issue with a simple reproduction repository
hdaklue
hdaklue15mo ago
did you try to change Reactive to ->live() for some reason that helped me sometimes
triad
triadOP15mo ago
No let me try that now
hdaklue
hdaklue15mo ago
also ->live(true) helped
triad
triadOP15mo 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 Harrin15mo ago
live() === reactive() live is just the new version that stays in line with livewire 3
triad
triadOP15mo 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
triadOP15mo ago
the bot closed it automatically because i only put "see reproduction repo" in steps to reproduce
Dan Harrin
Dan Harrin15mo ago
please just write what file to look in etc what url to visit
triad
triadOP15mo 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