Hi all,
I am trying to call a custom error function.
The function was set in /admin/config/validation/clientside_validation/default under "Custom function name".
Then I declared the function into a theme JS file, so it's globally defined.

This used to work on a 6.x version of Clientside Validation module, but when porting to 7.x-1.34, the browser returns the following error:

Uncaught TypeError: Object [object Object] has no method 'webform_validate_message' clientside_validation.js:537

Investigating clientside_validation.js I found this line to be the problem (clientside_validation.js:537):

Drupal.myClientsideValidation[func](error, element);

Since the function is declared document-wide and not inside Drupal.myClientsideValidation[func], it won't find it.

Then I tried to change my function declaration to:

Drupal.myClientsideValidation['webform_validate_message'] = function (error, element) { ... }

But still won't work, since Drupal.myClientsideValidation is an object and not an array.

So the solution I found was changing line 534 of clientside_validation.js to the same as 6.x version:

        case 7:
          validate_options.errorPlacement = function (error, element) {
            window[self.forms[f].customErrorFunction](error, element);
          }
          break;

That worked.

Am I doing something wrong when setting my custom error message function? Or it is a bug?

Regards,
Allan.

Comments

adenot’s picture

Just an extra information:
Using the latest D6 version also breaks, the code that worked was found in an older D6 version.

Jelle_S’s picture

Here's my code which works as expected:
cv_test.module

/**
 * Implements hook_form_alter().
 */
function cv_test_form_alter() {
  drupal_add_js(drupal_get_path('module', 'cv_test') . '/cv_test.js');
}

cv_test.js

(function($){
  Drupal.behaviors.cvtest = {
    attach: function() {
      $(document).bind('clientsideValidationInitialized', function() {
        Drupal.myClientsideValidation.cv_message = function(error, element) {
          alert($(error).text());
        }
      });
    }
  }
})(jQuery);
adenot’s picture

Category: bug » support

Thanks Jelle_S, it worked like a charm.

Would that be the case to update the module documentation to include this hint?

I can help with that.

Regards,
Allan.

Jelle_S’s picture

Issue tags: +Needs documentation

This needs documentation indeed. Any help is of course appreciated.

kwoxer’s picture

Hey I have the same Issue. I'm using latest Version of Clientside Validation and when I try to set a custom function in the backend. And then submitting a form in the frontend. I'm getting:

Drupal.myClientsideValidation[func] is not a function

But how can that be? I put in there the same original method given with the plugin. So I did not change anything. If I leave the field empty (not setting the custom method) it at least does not give an error.

kwoxer’s picture

Issue still persists. Ist there something new about this? Would love to hear some ideas.

Jelle_S’s picture

@kwoxer
Did you follow the code example above? Could you show me your code?

kwoxer’s picture

Nvm, I implemented it in a wrong way. Now it works properly. (I edited the given JS file instead of creating an own).

But I have another issue with this Module. Maybe you have a solution on this?
http://stackoverflow.com/questions/40023775/jquery-validation-message-re...

Jelle_S’s picture

Status: Active » Closed (works as designed)
kwoxer’s picture

Status: Closed (works as designed) » Active

Thanks for your help. Everything working now properly.

Jelle_S’s picture

Status: Active » Closed (works as designed)

No problem

kwoxer’s picture

Status: Closed (works as designed) » Closed (outdated)

I would say it's outdated and the "workaround" from jelle_S" is ok. WDYT?