Copy link to clipboard
Copied
I am trying to set the properties of a few form fields as required in case a specific value is chosen from a drop down list.
I entered the below code to the actions tab of the dropdown properties>Mouse Down>Run a java script. The problem is that it only works if I exit and reenter the dropdown. I tried invoking the code with "Mouse down", "Mouse Enter", Mouse Exit" none of them worked unless I go out and in again to the dropdown list.
Any suggestions?
Thank you!
var devused=this.getField("Device used");
var comptype=this.getField("Type of complaint");
var proname=this.getField("Product name");
var sent=this.getField("Sent to Sponsor");
if (comptype.value=="Product related complaint") {
devused.required=true;
proname.required=true;
sent.required=true;
}
else {
devused.required=false;
proname.required=false;
sent.required=false;
}
What you are describing is the documented way in which Acrobat forms and Acrobat JS behave per Form Event Processing
For your form a described, one could use a custom format script for the drop down field:
if(event.willCommit != true && event.changeEx != " ")
{
var devused = this.getField("Device used");
var proname = this.getField("Product name");
var sent = this.getField("Sent to Sponsor");
switch(event.changeEx)
{
case "Product related complaint" :
devused.required=true;
proname.required=tru
Copy link to clipboard
Copied
To get an immediate effect, you have set the option to commit value immediately and use the custom keystroke fomat to run a custom format script that sets the read only proerty of another field. You use the changex property not the field value.
Copy link to clipboard
Copied
I tried looking for some examples but was unable to find something that works (coding is not my strong side). any chance you can post an example for a code I have to put in the custom keystroke script and the custom format script fields?
Many thanks for helping.
Copy link to clipboard
Copied
Works perfectly thank you so much!!!
Copy link to clipboard
Copied
Assuming that the dropdown you're working with is the "Type of complaint" field and you're not using export values for the dropdown items, you can remove any of the scripts that may still be present and use the following custom Validate script:
// Custom Validate script for dropdown
(function () {
// Get the selected value of this dropdown
var comptype = event.value;
// Get references to other fields
var devused = this.getField("Device used");
var proname = this.getField("Product name");
var sent = this.getField("Sent to Sponsor");
if (comptype == "Product related complaint") {
devused.required = true;
proname.required = true;
sent.required = true;
} else {
devused.required = false;
proname.required = false;
sent.required = false;
}
})();
If you select the "Commit selected value immediately" option, the other fields will be affected when the user selects a dropdown item.
Copy link to clipboard
Copied
What you are describing is the documented way in which Acrobat forms and Acrobat JS behave per Form Event Processing
For your form a described, one could use a custom format script for the drop down field:
if(event.willCommit != true && event.changeEx != " ")
{
var devused = this.getField("Device used");
var proname = this.getField("Product name");
var sent = this.getField("Sent to Sponsor");
switch(event.changeEx)
{
case "Product related complaint" :
devused.required=true;
proname.required=true;
sent.required=true;
break; // skip to end of switch;
// repeat above fdor each option value in dropdown;
default:
// if no match to the above cases found;
devused.required=false;
proname.required=false;
sent.required=false;
break;
} // end switch event.changeEx;
} // end willCommit not true;
You need to set the "Commit selected value immediately" and as one moves up or down the options the associated fields will change and remain set when leaving the field Note that the field's name is not used in the script since the field is the event object until one leaves the field.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now