How to validate a modal form before extraModalFooterActions runs?
I have a modal with a form and a custom footer button. I need to validate the form when this custom button is clicked, before its own logic runs.
However, the action's ->before() hook is never triggered, so I can't run validation.
Here is a simplified example of my code:
Is there a way to validate the form before proceeding to the modal footer action? (I don't want to validate by ->required())
9 Replies
this is how i do it:
you will need to manually trigger the validation.
No need to do the above, just run:
$formData = $this->form->getState();
This runs the validation and only returns the formData for saving.
so:
When clicking the 'Confirm' button, it proceeds to the confirmation modal. What I want is to prevent the confirmation modal from opening if the form hasn't passed validation. If I use $this->getSaveDraftAction() or $formData = $this->form->getState() in extraModalFooterActions, the confirmation modal still opens immediately. Is there another way to achieve this?

Not before confirmation that I am aware
I have tried this solution and that did not work for me. Which is why I provide my solution.
getState runs the entire form validation, if it isn't then you likely haven't mounted your data correctly. Or you want individual validations to be run which yours will do.
probably the reason it does not work for me is because i create a custom action class.
More than likely then, it'll be down to the form filling I suspect on your custom action. Though I haven't gone that deep as not needed too as of yet.