Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I would like to have the ability to handle the submission of the form myself after client side validation has been completed.
My approach is to add a submitHandler into the validation options and the relevant admin interface to flag it on and off.
I will submit an attempted patch soon.
Comments
Comment #2
roflcopterDorrie CreditAttribution: roflcopterDorrie commentedComment #3
roflcopterDorrie CreditAttribution: roflcopterDorrie commentedAn example of the submit handler in action:
Comment #4
welly CreditAttribution: welly at PreviousNext commentedTested this on a project that I needed this functionality working on. Works great! The only thing I would suggest is the bind event name 'clientsideValidationFormDoesNotHaveErrors' is a little unwieldy. I've updated the patch with a slightly more concise bind event name 'submitHandler', see attached. But aside from that, great patch!
Edit. as an after thought, the bind event probably needs something suggesting it's specifically for clientside validation. But something a little more concise than the original all the same!
Comment #5
hugronaphor CreditAttribution: hugronaphor as a volunteer and at Acrosto for Dropsolid commentedThe patch works great.
Regarding the event name, I think we should follow the existing names style so: "clientsideValidationFormSubmitHandler" should be ok.
As I'm using the 2.x version, I'll leave here the patch for the 7.x-2.x branch
And an example to have it globally:
Comment #6
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedI've improved patch from #5, because when there is no custom submit handler - form will not be submitted.
Comment #7
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedComment #8
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedFixed name of event in description of new setting.
Comment #9
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedpatch from #8 can break ajax forms even if don't bind 'clientsideValidationFormSubmitHandler' event with it.
I think we must not submit form e.g
form.sumit();
insubmitHandler
, but need to prevent submission or return true.I've used idea from https://www.drupal.org/project/clientside_validation/issues/2898885 and added submitHandler
and created custom behavior for specific form with some class:
Comment #10
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commented