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

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

Explorer ,
Jul 25, 2024 Jul 25, 2024

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.

TOPICS
How to , PDF , PDF forms
561
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jul 25, 2024 Jul 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}

View solution in original post

Translate
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 ,
Jul 25, 2024 Jul 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}

Translate
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
Explorer ,
Jul 25, 2024 Jul 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!)

Untitled-1.jpg

Translate
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 ,
Jul 25, 2024 Jul 25, 2024

You copied a bunch of text that isn't a part of the code...

Translate
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
Explorer ,
Jul 25, 2024 Jul 25, 2024

So I did! I paid closer attention, and the scripts do exactly what I needed!!

Translate
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 ,
Jul 25, 2024 Jul 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.

Translate
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
Explorer ,
Jul 25, 2024 Jul 25, 2024
LATEST

Thanks, yes, I figured it out finally. Thank you for your help, it works perfectly.

Translate
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 ,
Jul 25, 2024 Jul 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.

Translate
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
Explorer ,
Jul 25, 2024 Jul 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!

Translate
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