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

Setting form fields as required based on dropdown entry

New Here ,
Aug 07, 2016 Aug 07, 2016

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; 

}

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
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

correct answers 1 Correct answer

LEGEND , Aug 07, 2016 Aug 07, 2016

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

...
Translate
LEGEND ,
Aug 07, 2016 Aug 07, 2016

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.

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
New Here ,
Aug 07, 2016 Aug 07, 2016

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.

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
New Here ,
Aug 07, 2016 Aug 07, 2016
LATEST

Works perfectly thank you so much!!!

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
LEGEND ,
Aug 07, 2016 Aug 07, 2016

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.

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
LEGEND ,
Aug 07, 2016 Aug 07, 2016

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.

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