Check dirty state of a form
Hey, is there any way to check if a form is dirty ? I need to check the form in its entirety and not only a single field so I can't call variables of the page
13 Replies
where do you want to check it from and why?
I want to check it within my livewire component (I'm only using forms not admin) to display a message when there are unsaved changes
i dont think theres an easy way to do that
you would need to compare the form data with the Eloquent record
do you have any idea how I could achieve this ?
I don't know how difficult it would be to compare as I have repeaters and builders within my forms so I'm a bit scared of what's needed to be done
I don't know what you think about that but using
Any way to check data state ?
wire:target is not displaying when changing any field :
<span wire:dirty wire:target="data">Unsaved changes</span>
if i knew, i would say. sorry
Why not just use the dirty method direction?
Load the record, set the model values with the new values, then model->getDirty() will show what has changed?
Still I appreciate you taking time to answer π
I was pretty sure there was a function but couldn't remember at what level ... Seems like it was Laravel π
Will this work with defer, relations and morphed input (those that are rearranged before save don't know if you see what I mean) ?
Not too sure how you mean
Something like $input1, $input2, $input3 declared in forms
And when saving
It's a bit more messy but this is the point
Tell me if you still don't see I'll get you a piece of code I have when I get back on it π
Why would you do that?! Why not just update($this->form->getState()) ?
Mainly for some complex relationship I have that I can't directly pass to forms the way they are done, I'm adapting a package to another use that is not meant and trying not to change it too much to keep it updated
I do almost the same as mutateBeforeSave in admin iirc
here is a much better example of something I do in the save method
But why are you not just updating everything? Why are you being so specific?
because of the needed classes like for TranslatedText here
as for now there is only fr but shortly I'll add more translations this is why I need this class