Help Creating Conditional Required Fields

Apr 17, 2019

Copy link to clipboard

Copied

Hello everyone,

Management wants me to create a form with two columns that can "interact" with one another. The first column is a code column using 'list' boxes with options 1, 2 ,3, O, and X. This column is titled "Code" and each box is titled "List Box 9" and the list continues to "List Box 21". The second column is just a comment column that is not required unless the option 'X' is selected in the first column. This column is titled "Repair Comments" and each text box is titled "24 Repair Comments 9" and the list goes on to "24 Repair Comments 21". Management wants the boxes in the "Repair Comments" column to be required if 'X' is selected in the list boxes under the "Code" column.

For example:

If "List Box 9" is blank or has codes 1, 2, 3, or O, then the text box "24 Repair Comments 9" should not be required to fill out. However, If "List Box 9" is changed to an 'X', then "24 Repair Comments 9" should turn into a required field.

Is this possible? Would I enter this as a validation script or calculation script? Should the script be entered in "List Box 9", "24 Repair Comments 9", or a completely separate field? Keep in mind this condition needs to apply to the list boxes and comments from 9 to 21. I heard it is better to keep the scripts in a separate field, but I don't know why.

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

322

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

Help Creating Conditional Required Fields

Apr 17, 2019

Copy link to clipboard

Copied

Hello everyone,

Management wants me to create a form with two columns that can "interact" with one another. The first column is a code column using 'list' boxes with options 1, 2 ,3, O, and X. This column is titled "Code" and each box is titled "List Box 9" and the list continues to "List Box 21". The second column is just a comment column that is not required unless the option 'X' is selected in the first column. This column is titled "Repair Comments" and each text box is titled "24 Repair Comments 9" and the list goes on to "24 Repair Comments 21". Management wants the boxes in the "Repair Comments" column to be required if 'X' is selected in the list boxes under the "Code" column.

For example:

If "List Box 9" is blank or has codes 1, 2, 3, or O, then the text box "24 Repair Comments 9" should not be required to fill out. However, If "List Box 9" is changed to an 'X', then "24 Repair Comments 9" should turn into a required field.

Is this possible? Would I enter this as a validation script or calculation script? Should the script be entered in "List Box 9", "24 Repair Comments 9", or a completely separate field? Keep in mind this condition needs to apply to the list boxes and comments from 9 to 21. I heard it is better to keep the scripts in a separate field, but I don't know why.

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

323

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
Apr 17, 2019 0
Most Valuable Participant ,
Apr 18, 2019

Copy link to clipboard

Copied

Yes, it's possible. I would do it from a completely separate field, to keep the code short, concise and located in a single spot.

Create a (hidden) text field and apply the following code as its custom calculation:

for (var i=9; i<=21; i++) {

    this.getField("24 Repair Comments "+i).required = (this.getField("List Box "+i).valueAsString=="X");

}

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...
Apr 18, 2019 1
Apr 22, 2019

Copy link to clipboard

Copied

Thank you try67,

I was wondering if there is a script I can add to make the fields in '24 Repair Comments' change in appearance if X is entered as the code. For example, could it highlight as red to notify the user that the field is required or a message letting them know? Also, is there a script that would then prevent the user from saving or printing the file if X is entered and the requirement has not been fulfilled? Management just generally wants to deter users from finding a work around after entering the X. They really want those repair comments I guess.

If not then this will have to do.

Thank you again!

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...
Apr 22, 2019 0
try67 LATEST
Most Valuable Participant ,
Apr 22, 2019

Copy link to clipboard

Copied

1. Yes. You can use something like this:

this.getField("24 Repair Comments "+i).fillColor = (this.getField("List Box "+i).valueAsString=="X")  ? color.red : color.transparent;

2. Not quite. You can't prevent the user from saving or printing the file entirely, but the closest you can get to it is to display an error message, either in an alert box or on the actual page itself, and/or to force the fields in the saved/printed copy to be blank. You can achieve that using this (paid-for) tool I've developed: Custom-made Adobe Scripts: Acrobat -- Validate Required Fields Before Printing or Saving

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...
Apr 22, 2019 0