Modal in getHeaderActions keeps submitting parent form
I might just be bad at RTFM'ing, but whatever I do my submit action in my modal in getHeaderActions keeps trying to submit the actual resource form. The action:
Anything to stop this from happening? I just need the modal form to be submitted, in this case save the form template, not the whole resource with it.
15 Replies
I simply do not understand what's happening
even $data is empty
Is it actually submitting the form or just showing validation errors? You’re referencing the livewire component in your action which is actually the page and not the actions’ form.
validation errors about required fields, I assumed it's trying to submit it
$livewire->form->getState() runs the validations for the form before save. I think that’s what you’re seeing.
question is why is it running validations on the resource form
not on the action form
Because your referencing $livewire which is the page not the action form.
nvm I'm tired I read like an idiot
Actions are not livewire components, pages are.
In an ->action() $data is the action’s form data.
so assuming that form->getState() tries to validate the whole form, anything that can grab all the current field values off the form?
If you need the pages form data in your action without the validation then $livewire->form->getRawState()
But in an action you are responsible for validation, etc. think of it as a controller.
I just need a dump of all the current populated fileds, I don't care for validation
I'll check with getRawState in a sec
One thing to be aware of is that get raw state doesn’t persist fileuploads if you have them, just another thing that ->getState() handles other than validation.
Since the form is huge and lots of the fields are boilerplate for certain "clients", the idea was to make a template that you can save once then pre-fill the form
getRawState seems to be working perfectly for this so far
thank you ❤️
I assume I can just
fillForm
this data back, but that's a help question for tomorrow 😄Glad it’s working for you. But yea, get some sleep.
fyi yeah it just worked with fillForm with no additional magic needed, thanks again