Copy a validation java script into multiple fields

Community Beginner ,
Sep 19, 2018

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

162

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Copy a validation java script into multiple fields

Community Beginner ,
Sep 19, 2018

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

163

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 19, 2018 0
Adobe Community Professional ,
Sep 20, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2018 1
Most Valuable Participant ,
Sep 20, 2018

Copy link to clipboard

Copied

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;

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2018 1
Community Beginner ,
Sep 20, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2018 0
Most Valuable Participant ,
Sep 20, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2018 1
Community Beginner ,
Sep 20, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 20, 2018 1