Require certain fields based on combo box selection

New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

I have created a dynamic form in Acrobat DC where selecting a button will make certain fields required and/or suggested (using green border around the field). I was able to do this successfully with everything but the combo box. I need to be able to make certain fields (text and checkboxes) required or suggested based on the selection in the combo box. I haven't been able to find exactly what I'm looking for googling this. Any help is greatly appreciated!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, I see the issue. You need to use the display value instead of the export value when using event.value.

So instead of:

if (event.value == "1")

Use:

if (event.value == "A-FSET")

TOPICS
Acrobat SDK and JavaScript, Windows

Views

582

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

Require certain fields based on combo box selection

New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

I have created a dynamic form in Acrobat DC where selecting a button will make certain fields required and/or suggested (using green border around the field). I was able to do this successfully with everything but the combo box. I need to be able to make certain fields (text and checkboxes) required or suggested based on the selection in the combo box. I haven't been able to find exactly what I'm looking for googling this. Any help is greatly appreciated!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, I see the issue. You need to use the display value instead of the export value when using event.value.

So instead of:

if (event.value == "1")

Use:

if (event.value == "A-FSET")

TOPICS
Acrobat SDK and JavaScript, Windows

Views

583

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
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

There shouldn't be an issue to do it, although it's possible the built-in required fields validation will ignore these fields.

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...
Dec 29, 2017 0
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

Sorry, but I don't know how. I am only able to get it to work if I choose something from the combo box, go to another field, and go back to the combo box. When I click on the dropdown arrow, that is when it works. The javascript I have under Mouse Up is:

var PrimaryCARESAccess = this.getField("PrimaryCARESAccess");

var IMDropdown = this.getField("IMDropdown");

if (PrimaryCARESAccess.value == "1") {IMDropdown.required = true;}

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

Use this code as the validation script of the drop-down:

var IMDropdown = this.getField("IMDropdown");

if (event.value == "1") {IMDropdown.required = true;}

Also, make sure to tick the option to commit the selected value immediately, under Properties - Options.

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...
Dec 29, 2017 0
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

Sorry but it doesn't work. It only works when I choose the item in the combo box and then click on the combo box a second time.

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

Did you move the code to the Validation script?

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...
Dec 29, 2017 0
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

Yes

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

And just to clarify, the combo-box is "PrimaryCARESAccess", right?

If so, can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?

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...
Dec 29, 2017 0
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

Here is the file: f00476 12 20 17 DRAFT.pdf - Google Drive

I'm trying to get the basic code and instructions so that I can use it to create different scenarios for the various selections in the combo box.

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

OK, I see the issue. You need to use the display value instead of the export value when using event.value.

So instead of:

if (event.value == "1")

Use:

if (event.value == "A-FSET")

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...
Dec 29, 2017 1
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

Yes! That did the trick! Thank you very much. I was able to incorporate all the selections.

If the person filling this out chooses one and then decides it was the wrong choice, is there code so that the required/suggested fields associated with the first choice are "reset"?

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

Sure. You can use something like this:

this.resetForm(["Field1", "Field2", "Field3"]);

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...
Dec 29, 2017 0
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

I guess reset is the wrong word to use. I'm looking at undoing required and suggested (fields with green border). For example, if "C-Children First" is selected but the person actually wanted "B-Resource Specialist/Job Coach," how would I change "IndividualOffice" from being required to not being required? Reseting a form doesn't change the required property.

// mark required

if (event.value == "C-Children First") {IndividualOffice.required = true; OfficeNumber.required = true; IndOffice.required = true;}

if (event.value == "Y-Transitional Jobs") {IndividualOffice.required = true; OfficeNumber.required = true; IndOffice.required = true;}

if (event.value == "H-Receptionist-IM") {IMDropdown.required = true;}

if (event.value == "M-IM Worker") {IMDropdown.required = true;}

if (event.value == "U-IM Supervisor") {IMDropdown.required = true;}

// mark suggested

  1. color.green= ["RGB",0,1,0];

if (event.value == "A-FSET") {Region1.strokeColor = ["RGB",0,1,0]; Region2.strokeColor = ["RGB",0,1,0]; Region3.strokeColor = ["RGB",0,1,0]; Region4.strokeColor = ["RGB",0,1,0]; Region5.strokeColor = ["RGB",0,1,0]; Region6.strokeColor = ["RGB",0,1,0]; Region7.strokeColor = ["RGB",0,1,0]; Region8.strokeColor = ["RGB",0,1,0]; Region9.strokeColor = ["RGB",0,1,0]; Region10.strokeColor = ["RGB",0,1,0]; Region11.strokeColor = ["RGB",0,1,0];}

if (event.value == "A-Job Coach") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

if (event.value == "B-Resource Specialist/Job Coach") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

if (event.value == "H-Receptionist-W-2") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

if (event.value == "J-Financial Employment Planner (FEP) Supervisor") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

if (event.value == "N-FEP") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

if (event.value == "P-Resource Specialist") {FSC.strokeColor = ["RGB",0,1,0]; MIEC.strokeColor = ["RGB",0,1,0]; MIN.strokeColor = ["RGB",0,1,0]; MIS.strokeColor = ["RGB",0,1,0]; MIWC.strokeColor = ["RGB",0,1,0]; NorthCentral.strokeColor = ["RGB",0,1,0]; Northeast.strokeColor = ["RGB",0,1,0]; Northwest.strokeColor = ["RGB",0,1,0]; Southeast.strokeColor = ["RGB",0,1,0]; Southwest.strokeColor = ["RGB",0,1,0]; Western.strokeColor = ["RGB",0,1,0];}

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...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

Before your if-statements set the fields as not required, like this:

IndividualOffice.required = false;

OfficeNumber.required = false;

IndOffice.required = false;

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...
Dec 29, 2017 1
New Here ,
Dec 29, 2017

Copy link to clipboard

Copied

This works great! Thank you so much for your help!

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...
Dec 29, 2017 0