• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Custom validation script doesn't work on certain text boxes

Community Beginner ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

I have the following custom validation script on a text box:

varClientName = event.value;
this.getField("Client Name pg16").value = varClientName;
this.getField("Client Name pg17").value = varClientName;

to autopopulate names further in the document. In this example, the name successfully was added to text box "Client Name pg16", but not "Client Name pg17".  However, if I use "Prepare a Form" and I move text box "Client Name pg17" and then undo that move, the validation script does then work on that textbox.
I cannot possibly be expected to move each and every textbox each time I want to run a validation script. How can I solve this issue?

TOPICS
JavaScript , PDF , PDF forms

Views

375

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 14, 2024 Jun 14, 2024

Do the other fields have a calculated value as well? If so, you need to check the fields calculation order, under More in Prepare Form mode.

Votes

Translate

Translate
Community Expert ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

It should fill both fields at the same time, can you share your file with us?

If you wish to autopopulate those fields there is an easier solution, just give all 3 fields the same name, fields with the same name have the same value, there is no need for script.

Votes

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
community guidelines
Community Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Thank you for the help. Unfortunately I cannot share the document I'm sorry. Using the same label/name for each text box won't work for me either since some information will not be the same in each textbox, multiple people will be handling this document, and I do not want changes to a textbox further in the document to alter the information that was previously entered. My goal is to have the earlier textboxes autopopulate further down in the document, but allow changes to those later textboxes without alterring the earlier textboxes. I'm wondering if it's an issue of having too many textboxes and validation scripts in a single document?

Votes

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
community guidelines
Community Expert ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

No, that's not likely. It's much more likely there's a problem with your code. Did you check the JS Console?

Votes

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
community guidelines
Community Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Thanks for the help. I'm not sure what the issue could be with the code, it's a very simple script and the same exact code works for about 90% of the textboxes and has been working for a while, it's just a few that have stopped autopopulating very recently. The debugger says getField is returning Null, but I copied and pasted the name of the textbox into the script so I'm not quite sure what's causing that. I've attached screenshots of the script, and the textbox it's meant to autopopulate into. The script works just fine for autopopulating into the textbox on pg14, but the one for pg15 does not. I have double checked, the textbox name is not the issue

Votes

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
community guidelines
Enthusiast ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

If there's an error in your first line of code (missing field or misspelled field name), the second line won't run.  If there's a calculation error somewhere else, the code will stop when the error is thrown.  Try copying the 3 fields in question to blank PDF with no other fields and see if the code works or if there are any errors in the console.  Make sure there are no scripts left behind in the calculation and format tabs of your field.

Votes

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
community guidelines
Community Expert ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Try a script like this:

this.getField("Client Name pg16").value = event.value;
this.getField("Client Name pg17").value = event.value;

Votes

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
community guidelines
Enthusiast ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Answered below on Jun 7.

Votes

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
community guidelines
Enthusiast ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

There should be space after var to name the variable, and then no var with the next two client names like this:

 

var ClientName = event.value;
this.getField("Client Name pg16").value = ClientName;
this.getField("Client Name pg17").value = ClientName;

 

An easier way to write this script is:

this.getField("Client Name pg16").value = event.value;
this.getField("Client Name pg17").value = event.value;

 

However, I tested your script and it work for me.  Like Nesa Nurani said, just name all the fields the same, unless you need the user to be able to change the values after they have been validated, while leaving the value in the data entry field untouched.

 

 

Votes

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
community guidelines
Community Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Thanks for the help, I replaced my script with yours but unfortunately I'm still having the same issue. Only some of the boxes are autopopulated, but moving the unpopulated boxes in "Prepare a Form" mode then causes it to autopopulate when I try again. I've noticed it's certain pages that are the issue, but cannot figure out why.

Votes

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
community guidelines
Community Expert ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Do the other fields have a calculated value as well? If so, you need to check the fields calculation order, under More in Prepare Form mode.

Votes

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
community guidelines
Community Beginner ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much!!!
Have not been able to get this working for a week, and I have asbolutely no clue how that checkbox got checked, but it was set to calculate to blank U+2800 character. I was about to completely start over. This is an old document but still no clue how this happened

Thanks for all the help @PDF Automation Station @try67 @Nesa Nurani 

Votes

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
community guidelines
Enthusiast ,
Jun 14, 2024 Jun 14, 2024

Copy link to clipboard

Copied

Votes

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
community guidelines