Get old state

I have two components in a Form. I can copy the value over from one component to the other. Now I want to have an action to undo this. I tried the following:
->hintAction(
Action::make('undoJobTitle')
->label('Herstel oude waarde')
->icon('heroicon-m-clipboard')
->action(function ($component, $livewire, $state, $set) {

dd($component->getLivewire()->getOldFormState($component->getStatePath()));

})
->hintAction(
Action::make('undoJobTitle')
->label('Herstel oude waarde')
->icon('heroicon-m-clipboard')
->action(function ($component, $livewire, $state, $set) {

dd($component->getLivewire()->getOldFormState($component->getStatePath()));

})
Also, this:
dd($component->getOldState());
dd($component->getOldState());
Both return null after I changed the value of the field. Not sure if I'm doing it right. Maybe I have to save the form first, but that is not what I want. Any ideas?
3 Replies
cheesegrits
cheesegrits15mo ago
Are you using $set in a closure to copy the value? Or do you literally mean you are copying and pasting values? I ask because I'm pretty sure using $set to change the state of a field will not update the oldFormState array, as that gets handled by a magic Livewire update method, which I'm pretty sure only gets called when attributes are updated through Livewire. The $set callable just directly calls data_set on the form data.
cheesegrits
cheesegrits15mo ago
For example, here's the Filament demo app, where it uses afterStateUpdated() on 'name' to set the 'slug'. As you can see, updatingInteractsWithForms() (the magic Livewire method) gets called to update oldFormState[] for data.name as I blur our of the name field, but doesn't get called when the 'slug' gets updated with $set.
cheesegrits
cheesegrits15mo ago
So if you are doing the 'job-title' (or whatever) copy programatically, you might be able to manually update oldFormData through $livewire.
Want results from more Discord servers?
Add your server