I have a custom form built with the Forms API and my elements have custom AJAX callbacks. When I click on an element with AJAX callback, I get an JavaScript error from the Clientside Validation IFE module.

Thank you for looking at this.

The error is getting thrown from this function:

(/** @lends Drupal */function ($) {
  "use strict";
  /**
   * Drupal.behaviors.clientsideValidationHtml5.
   *
   * Attach clientside validation to the page for HTML5.
   */
  Drupal.behaviors.clientsideValidationIfe = {
    attach: function () {
      $(document).bind('clientsideValidationInitialized', function (){
        /**
         * IFE specific rules.
         * @name _bindIfeRules
         * @memberof Drupal.clientsideValidation
         * @method
         * @private
         */
        jQuery.each(Drupal.myClientsideValidation.validators, function (formid) {
          Drupal.myClientsideValidation.validators[formid].showErrors(Drupal.settings.clientsideValidation.forms[formid].serverSideErrors);
        });
      });
    }
  };
})(jQuery);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DianovVS’s picture

I fixed that problem with help that condition: if (Drupal.settings.clientsideValidation.forms[formid] !== undefined) {...}
Replace code in your file ...\clientside_validation_ife.js

(/** @lends Drupal */function ($) {
  "use strict";
  /**
   * Drupal.behaviors.clientsideValidationHtml5.
   *
   * Attach clientside validation to the page for HTML5.
   */
  Drupal.behaviors.clientsideValidationIfe = {
    attach: function () {
      $(document).bind('clientsideValidationInitialized', function () {
        /**
         * IFE specific rules.
         * @name _bindIfeRules
         * @memberof Drupal.clientsideValidation
         * @method
         * @private
         */
        jQuery.each(Drupal.myClientsideValidation.validators, function (formid) {
          if (Drupal.settings.clientsideValidation.forms[formid] !== undefined) { // <<< add condition here
            Drupal.myClientsideValidation.validators[formid].showErrors(Drupal.settings.clientsideValidation.forms[formid].serverSideErrors);
          }
        });
      });
    }
  };
})(jQuery);
DianovVS’s picture

Status: Active » Fixed
vlad.dancer’s picture

Status: Fixed » Needs review
FileSize
1.96 KB

Hi there!
@DianovVS, unfortunately this just fixes broken js but doesn't resolve the problem.
I believe the problem comes from clientside_validation_ife.module

function clientside_validation_ife_validator($form, $form_state) {
  ....
  clientside_validation_add_js_settings($settings); // SHOULD be $js_settings
}

+ in clientside_validation_ife.js should have some cleaning code to remove empty "ife" elements.
Below is the patch that fixes this issue.
Please review it!

attiks’s picture

Assigned: Unassigned » Jelle_S

  • Jelle_S committed ad66e04 on 7.x-1.x authored by vlad.dancer
    Issue #2268513 by vlad.dancer | jongagne: Fixed Uncaught TypeError:...
Jelle_S’s picture

Status: Needs review » Fixed

Fixed in latest dev. Thanks for the patch!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.