Is there a way to avoid duplicate afterStateUpdated methods ?
I have code like:
Simplified example; but basically, one field depends on two others. You have to have the same duplicated afterStateUpdated callback on both fields.
It'd be a load nicer not to duplicate this and just have it attached to the total field. Is there a way to do this at all ? I've had a good dig but can't find anything.
(I realise I can extract the method to a closure/other method; but it'd still be nice not to attach it twice)
Solution:Jump to solution
and..... simplest of all....
```
\Filament\Forms\Components\Section::make()
->columns([...
4 Replies
Extracting is probably the only option.
this works...
first, override on the page/livewire component:
then a field can listen for that event
kind of dirty/hacky
i think for my situation, it may be worth taking the hackiness here; my afterStateUpdateds are quite intertwined....
it's not just field 3 depends on field 1 and field 2
more
field a depends on field 1,2,3
field b depends on 1 + 4
field c depends on 2
so extracting out a closure is still messy
defining the callbacks on the target field rather than the source field is a whole load cleaner/nicer to work with
Solution
and..... simplest of all....
the callback will be 'busy' ; but i can separate that out
main thing is it's defined once; so it should be less brittle / easier to keep in good shape