How to apply custom javascript validation to fields that are defined in HTML code only?

floppysheep 26 Feb, 2020
Hello all, I'm trying to do a custom validation on {data:} fields that are not defined by a "Field" object in the "Design" tab, but are defined inside custom HTML sections in the design tab. And I'm having some difficulty.

If I understand this FAQ correctly, I can apply custom JS validation code to specific {data:} fields by adding "customjsfunction[params]:error message" to the validation rules under the "Validation" tab in the Field's Design tab.

However, my fields don't have "Field" objects in the Design Tab, so I've tried using a "Validate Data" object inside my "submit" action under the "Setup" tab.

Under "Setup Tab->Submit->Validation Data" I am able to specify one of the "default" custom validation rules on a field by entering a rule like "customfield/is_empty:error message", and that works. However, I can't seem to call a custom JS function properly here. I've tried two things:
  1. Entered a rule like "customfield/customjsfunction:errormessage". I get the error "Call to undefined method G2\L\Validate::customjsfunction()
  2. Entered a rule like "customjsfunction:errormessage", but this rule is never to called (I've tested by setting the rule to ALWAYS return false).

What am I doing wrong? How can I apply my own custom javascript validation rules to {data:} fields that don't exist as objects in the "Design" tab?
floppysheep 27 Feb, 2020
UPDATE: because of the time crunch on my project I've temporarily solved this in a kludgy way.

I found the predefined default custom field validation rules in the source code file /libraries/cegcore2/libs/validate.php and added my own function, then called it on the proper fields within the "Setup Tab->Submit->Validation Data" object. And it works.

However, I'd love to know a better way than hacking the source code to achieve this.
healyhatman 27 Feb, 2020
You can't put it in the Setup tab, that's for serverside stuff.
This topic is locked and no more replies can be posted.