Page 1 of 1

Attribute validation with global code

Posted: Sat Sep 14, 2013 5:22 am
by Bernie

Greetings.
I've been searching the forums, and haven't found the answer for my questions, so, here they go.
I'd like to validate a field FieldB based on two items:

  • The value of a field FieldA previous to FieldB in the form
  • The JS function I've designed in Client Scripts > Global > Pages with header/footer > Global Code, wich returns true/false depending on the value of the field FieldB.

Any ideas on how to do this? Any way to either send the value of A to be evaluated on the function or to use the value directly from the php code? (the field A is named x_FieldA on the source code).


Re: Attribute validation with global code

Posted: Sat Sep 14, 2013 8:19 am
by mobhar

For validating values using PHP, you can use "Form_CustomValidate" server event that belongs either to "Add" or "Edit" page. For this, you have to enable server validation from "PHP" -> "General Options" -> "Validation" -> "Server-side".

You can also use "Form_CustomValidate" client script that belongs to either "Add" or "Edit" page if you want to validate the value using Javascript.

Read "Server Events and Client Scripts" in the help file for further information and example.


Re: Attribute validation with global code

Posted: Sat Sep 14, 2013 9:37 am
by danielc

Add onchange event by Startup Script for your field A to trigger your js function. Also read: http://api.jquery.com/change/.


Re: Attribute validation with global code

Posted: Mon Sep 16, 2013 1:01 pm
by Bernie

mobhar and danielc, thanks for the prompt answer.
mobhar, I was trying something like that, but wasn't able to make it work. I'll try again.
danielc, I was looking for a solution more like yours, I'll give it a try for sure.


Re: Attribute validation with global code

Posted: Tue Sep 17, 2013 1:58 am
by Bernie

Me and a friend came with a very simple solution.
Just looked at the source code of the page generated, and used the name x_ClientType of the field to get it's value. The JS function in the Global Code now starts like this:

function checkValues(varV){
var variableJQ = $("#x_ClientType").val();
if(variableJQ == 'VIP') {
...

It works just dandy.