There will be cases where we want to handle the form submission in custom way, do some custom validations or AJAX / API calls before doing the form submit. Here if we bind the submit event of form clientside validation is not invoked.

To fix this, we can allow custom submit handler to be called in submitHandler of validate().

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nikunjkotecha created an issue. See original summary.

nikunjkotecha’s picture

Status: Active » Needs review
StatusFileSize
new697 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 2898885.patch, failed testing. View results

nikunjkotecha’s picture

Status: Needs work » Needs review
StatusFileSize
new2.06 KB

Fix for build failure and additional fix to allow other modules to destroy validator using objects stored in Drupal.cvValidatorObjects.

Status: Needs review » Needs work

The last submitted patch, 4: 2898885-4.patch, failed testing. View results

nikunjkotecha’s picture

Status: Needs work » Needs review
StatusFileSize
new2.21 KB
nikunjkotecha’s picture

Status: Needs review » Needs work

The last submitted patch, 6: 2898885-6.patch, failed testing. View results

nikunjkotecha’s picture

StatusFileSize
new1.07 KB

Removed the changed related to composer.json inside module. This will be handled separately in https://www.drupal.org/node/2784069 or some other ticket.

jelle_s’s picture

I'm not sure we need this functionality?

Developers can add their own submit handler to their forms in their js files like this:

(function ($, Drupal) {
  'use strict';

  Drupal.behaviors.cvCustom = {
    attach: function (context) {
      $(context).find('form').each(function() {
        var validator = $(this).validate();
        validator.settings.submitHandler = function(validator, form, event) {
          alert('custom submit handler');
        };
      });
    }
  };
})(jQuery, Drupal);
nikunjkotecha’s picture

@Jelle_S It was not updating after it's initiated once

jelle_s’s picture

Ah, strange. I'll try to create a proof of concept later on. If I can get it to work fairly simple, I'll add the method to the readme. If not, I'll have another look at the patch.

nikunjkotecha’s picture

I think if we only add Drupal.cvValidatorObjects or something to store all objects, it would allow other modules to modify settings. Submit handler being more common case I added in module js itself.

jelle_s’s picture

Component: Code » Documentation
Category: Feature request » Support request
StatusFileSize
new1.02 KB

Attached is a proof of concept that works for me (latest dev version of clientside validation 8.x-1.x. Can you confirm it works for you too?

If it does we might want to document this.

nikunjkotecha’s picture

@Jelle_S this works fine, I'll spend sometime tonight to create a documentation page from the code sample you shared :)

I see where I was missing, I was trying to use validate() with options again to bind the submit function.

nikunjkotecha’s picture

Status: Needs work » Closed (works as designed)

himanshu_jhaloya made their first commit to this issue’s fork.