Validation Custom Function Not Working

tohuw 21 Jan, 2015
In the "JS Code" section of the "Load JavaScript" event, I have the following:
function validateApiKeyId(el){
  if ( !el.val().match(/\b\d{7}\b/) ) {
    return false;
  } else {
    return true;
  }
}
function validateApiKeyCode(el){
  if ( !el.val().match(/\b([a-zA-Z]|\d){64}\b/) ) {
    return false;
  } else {
    return true;
  }
}


In the custom function, I use the respective function names, e.g. validateApiKeyId


No validation seems to occur at all - even if I also check a built-in validation option. The resulting class according to my web inspector is:
class="validate['custom:validateApiKeyId'] form-control"


I assume this comes down to some error in my JS, but I don't see an error in the console. Any ideas?
tohuw 21 Jan, 2015
Sorry, meant to say "In the custom function [field in the Validation section for the text box], I use the respective function names, e.g. validateApiKeyId"
tohuw 22 Jan, 2015
Any ideas? I'm stumped on this one.
tohuw 23 Jan, 2015
As an update, I tried removing the value for the function and added this to class:

validate['length[7,-1]']


That didn't work either.
tohuw 27 Jan, 2015
Can someone please take a look at this?
Max_admin 02 Feb, 2015
Hi CMG,

Sorry for the late reply!

I have just tested this code in a "Load JS" action and uses "test" in the "custom" box under the validation tab of a "text" field:

function test(el){
return false;
}

The validation has always failed, but when changing "false" to true the form could be posted, so you need to double check the rules in your code and make sure that they work as expected, try the following site for live regex testing:

http://www.regexr.com/

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tohuw 03 Feb, 2015
No worries, thanks for taking a look.

The regex matches as I expect.

The first rule ensures only 7 digits are provided, the second rule ensures that only 64 alphanumeric characters are entered.
tohuw 03 Feb, 2015
Answer
Huh, changed the name to "checkAPIKeyId" and "checkAPIKeyCode" and it worked... weird! I didn't change anything else, so I don't know... well, solved I guess?
Max_admin 03 Feb, 2015
Maybe there was a caching issue, because this change should not have any effect on the function call! :?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.