Skip to main content
Participant
September 20, 2018
Answered

Copy a validation java script into multiple fields

  • September 20, 2018
  • 4 replies
  • 922 views

Hi,

I have a PDF form which acts as an inspection report for a manufacturing process at my work. I am trying to digitise the report so they can use a tablet instead of hand writing and then scanning the documents into our system.

I have a simple validation script which turns the entered text into red for certain values:

function if (event.value=="WORN") event.target.textColor = color.red;

else event.target.textColor = color.black;

However i am not having much luck copying this script to all the text fields on the document (over 200 fields).

I have tried the solution outlined in this thread: faster way to copy a validation java script into multiple fields, i have set a Document JavaScript called validateField, i have then put the following script into it:

function validateField()

{

function if (event.value=="WORN") event.target.textColor = color.red;

else event.target.textColor = color.black;

}

But when i run the  JavaScript console it just adds validateField() into the Text Fields custom validation script section and not the script above. This is what i am running the the JavaScript Console:

for (i=1; i<=200; i++)

{

    this.getField("Text Field Condition.1."+i).setAction("Validate",'validateField()');

}

Am i missing something?

Regards,

Tim

This topic has been closed for replies.
Correct answer Bernd Alheit

You miss nothing. At validation the function will be executed.

4 replies

Participant
September 20, 2018

Thanks, im not sure why but i have come back to it this morning and made sure i referenced the right script and it now works.

Legend
September 20, 2018

You absolutely want to add ValidateField() to each field, not the lines of the script. Then, if you made a mistake or want to improve it, you only have to change the document level script, and all the fields are fixed or improved.

try67
Community Expert
Community Expert
September 20, 2018

Your function definition is incorrect and would cause a syntax error when you try to use it.

You need to drop the second "function" term, so like this:

function validateField() {

     if (event.value=="WORN") event.target.textColor = color.red;

     else event.target.textColor = color.black;

}

Participant
September 20, 2018

Thanks, i have made the change. I have it working now.

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
September 20, 2018

You miss nothing. At validation the function will be executed.