Post hidden fields to reset data
Hi there,
I have a resource-form with multiple steps, and on top of each step is a toggle to "enable" some fields visually. If the toggle is enabled, the form-fields are displayed which contains all sorts of input: text, (multi)-select with relations, repeaters, etc. All of this works perfectly. Psuedo-form to give you an idea:
As said: all works perfectly! Now I want to "reset" all the input on a specific step if the toggle is disabled. In other words: I want to set the fields to null, delete relations etc if the toggle is off.
I could do this "manually" using
mutateFormDataBeforeSave
for example (lots of if issets etc), but I would rather have the logic on the form itself to keep the logic grouped.
Is this even possible? I tried making an extension of a group, which creates hidden fields but this does not work well. Is there another way to do this?
Thanks in advance!3 Replies
us dehydrate and condition it with a closure?
->dehydrate(fn($get) => $get('my_field') === 'value')
thanks for the suggestion π this works in some cases but not for relations for example
I think I will create some model-observers to reset the fields for now
You can call $this->rawState I beleive to get the raw data. You can also write observers, or also use the after method.