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.
I'm trying to use clientside_validation for a custom exposed views filter form. All works fine if there is no AJAX or autosubmit involved. The problem is that for my form, both is. I guess that submitting is handled via the submit button's click event. Now is there a way to start validating a form from the outside, e.g. with a click handler of a button? I think this could work in my case, but I don't know how to do this.
Comments
Comment #1
attiks CreditAttribution: attiks commentedRelated to #1730952: Validate ajax submits clientside before doing ajax request it should work with Ajax, if the auto submit invokes click on the button it should work as well, but no idea how the auto submit is done. Is this part of views or a custom module/code?
Comment #2
Ronino CreditAttribution: Ronino commentedThank you for your fast reply.
I tried that without any success.
The autosubmit functionality is part of ctools (ctools/js/auto-submit.js) and used by views. It looks like there is no submit event involved that's why I would like to start validating when the submit button gets clicked.
How to start validation from the outside (something like $('#some-form').validate())? I found validate() somewhere in clientside_validation.js, but passes validate_options which I don't have access to. In #1486480: Clientside Validation while using an ajax callback you suggest using form.validate. Could you be more specific?
How to know if there are errors (something like $('#form').hasErrors()) to prevent the click event from being processed?
Thank you in advance.
Comment #3
attiks CreditAttribution: attiks commentedCalling $('#some-form').valid() should trigger the validation, the easiest is to bind it to the click event of the button (using custom javascript code)
http://docs.jquery.com/Plugins/Validation/Validator/numberOfInvalids gices you the number of errors
Comment #4
Ronino CreditAttribution: Ronino commentedattiks, you are my hero. It works for me with this code:
Thank you!