Skip to main content
Known Participant
July 25, 2024
Answered

Requiring Field #2 to be completed if Field #1 has been filled in?

  • July 25, 2024
  • 2 replies
  • 742 views

Hi Folks,

 

We print NCR (carbonless forms) that clients often want numbered. On our Requisition we have two fields, one for the starting number and one for the end number. I don't want to make the two fields required because the forms aren't always numbered, but I do want to require a client to input the last number if they input a start number. Any ideas how to do this? Thank you.

This topic has been closed for replies.
Correct answer PDF Automation Station

If you enter this custom validation script in the first field, a message will popup after they enter a value and then set the focus to the 2nd field (I named it "EndPage" in the script).

 

if(event.value)
{
app.alert("Please input the ending page number.");
this.getField("EndPage").setFocus();
}

To make the field required if the first field contains a value enter this script as a custom calculation script in the EndPage field:

if(this.getField("StartPage").value)

{event.target.required=true}

else

{event.target.required=false}

2 replies

try67
Community Expert
Community Expert
July 25, 2024

You can use the following as the custom calculation script of the second field:

 

event.target.required = (this.getField("StartNumber").valueAsString!="");

 

Be aware that the required property is only validated when the file is submitted, though, not when it's saved, printed or emailed, or anything like that.

Known Participant
July 25, 2024

Ah, OK, thanks. I need it to be visible always, as we print the Reqs and they travel with he Job bag. And thanks too for the prompt response!

PDF Automation Station
Community Expert
Community Expert
July 25, 2024

If you enter this custom validation script in the first field, a message will popup after they enter a value and then set the focus to the 2nd field (I named it "EndPage" in the script).

 

if(event.value)
{
app.alert("Please input the ending page number.");
this.getField("EndPage").setFocus();
}

To make the field required if the first field contains a value enter this script as a custom calculation script in the EndPage field:

if(this.getField("StartPage").value)

{event.target.required=true}

else

{event.target.required=false}

Known Participant
July 25, 2024

Hello, and thanks for the prompt reply!

 

I renamed my fields to StartPage and EndPage, but when I enter the script I get a Syntax Error...I've attached the screenshot. ( I have no experience with scripting, btw!)

PDF Automation Station
Community Expert
Community Expert
July 25, 2024

It's two different scripts for two different fields with "To make the field required if the first field contains a value enter this script as a custom calculation script in the EndPage field:" as my instructions in between.