Copy link to clipboard
Copied
Hello, I am trying to create a drop down box that has the options within auto-filled based on the selection from the previous box. I found code that worked on the forums, but any time a choice is made, it will revert back to whatever choice is listed first within the code.
Dropdown box 1 custom calculation script is:
switch (event.value) {
case "Select:":
this.getField("SubProvType").setItems(["Please Make a Selcetion In The Previous Box First!"]);
break;
case "Choice1":
this.getField("SubProvType").setItems(["A","B","C","D"]);
break;
case "Choice2":
this.getField("SubProvType").setItems(["E","F","G","H"]);
break;
}
This will display the correct options in the second box, but if Choice1 is selected in the first box, then any choice made in the second box reverts back to "A" instantly. Is there something I can add to the code or some option that can be selected that will allow the chosen "Letter" to remain chosen, or will it always revert back to the first option listed in the code?
Copy link to clipboard
Copied
I can't see "Letter" in your lists. You can set the selection only on one of the items in the list.
Copy link to clipboard
Copied
If you're running this script as a custom calculation script in the "Select" field , You need to to add an additional line at the beginning of your script like this:
if (event.source && event.source.name=="myDropdown") {
switch (event.value) {
case "Select":
this.getField("SubProvType").setItems(["Please Make a Selcetion In The Previous Box First!"]);
break;
case "Choice1":
this.getField("SubProvType").setItems(["A","B","C","D"]);
break;
case "Choice2":
this.getField("SubProvType").setItems(["E","F","G","H"]);
break;
}
}
Just replace "myDropdown" with the actual name of your primary dropdown fieldname.
This will allow to make a choice in this field and then in the "SubProvType" field whatever you select from the list will stay selected and you can continue to work with other fields in your PDFs.
The options that you've chosen in "SubProvType" will stay selected and will change only when the user manually selects another option in the "Select" dropdown menu.
Copy link to clipboard
Copied
Or just move the original code to the field's Validation script, instead of Calculation...