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
Comment #1
adenot CreditAttribution: adenot commentedJust an extra information:
Using the latest D6 version also breaks, the code that worked was found in an older D6 version.
Comment #2
Jelle_SHere's my code which works as expected:
cv_test.module
cv_test.js
Comment #3
adenot CreditAttribution: adenot commentedThanks 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.
Comment #4
Jelle_SThis needs documentation indeed. Any help is of course appreciated.
Comment #5
kwoxer CreditAttribution: kwoxer commentedHey 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.
Comment #6
kwoxer CreditAttribution: kwoxer commentedIssue still persists. Ist there something new about this? Would love to hear some ideas.
Comment #7
Jelle_S@kwoxer
Did you follow the code example above? Could you show me your code?
Comment #8
kwoxer CreditAttribution: kwoxer commentedNvm, 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...
Comment #9
Jelle_SComment #10
kwoxer CreditAttribution: kwoxer commentedThanks for your help. Everything working now properly.
Comment #11
Jelle_SNo problem
Comment #12
kwoxer CreditAttribution: kwoxer commentedI would say it's outdated and the "workaround" from jelle_S" is ok. WDYT?