2

I'm doing an ajax validation for duplicate check on link field in node form. When the link field is edited, an ajax call is triggered as programmed (using form api #ajax default blur event), it takes a while for the ajax response to reach browser, in the meantime the form gets almost ready to submit by user. Doing an early form submit (i.e before the receipt of ajax response) Drupal ajax API throws below error message in JavaScript alert box,

An AJAX HTTP request terminated unexpectedly
Debug information follows.
Path: /system/ajax
Status text:
Answer Text:
Ready State: 4

I have noticed this issue in a few contrib modules as well. I think the fix is to prevent submitting the form to server until the ajax request completes. Wondering to know if there is any way to set client side callback function in form api that I can use to stop form submit.

1

This might help you.

Drupal.behaviors.merchant = {
  attach: function(context, settings) {
    jQuery('form.node-form')
      .ajaxStart( function() {
          jQuery(this).submit(function() {
            return false;
          });
        })
       .ajaxStop( function() {
          jQuery(this).unbind('submit');
          jQuery(this).submit(function() {
            return true;
          });
        });
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.