Highlighted

Reset drop-down value to default when drop-down becomes hidden.

Community Beginner ,
Aug 23, 2020

Copy link to clipboard

Copied

Working with a few dropdowns, one is always visible and when a value is selected in it, another field  becomes visible. How can I tell the invisible dropdowns to return to a default value if they're invisible?

 

if (this.getField("Make").value == "Chevrolet") this.getField("Chevrolet Models") display = display.visible;

else if (this.getField("Make").value != "Chevrolet") this.getField("Chevrolet Models") display = display.hidden;

 

That's all I'm working with so far. It'll hide the field of course but if a value is selected in the newly visible field it will remain selected when the field is invisible. 

 

Halp plz!

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

First make sure that both dropdown menu fields are set to commit selected value immediately and disable to allow users to enter custom text.

 

Also add a space entry in the dropdown options lists. 

 

This is key in order to be able to use the "this.resetForm()" function or to use a condition  that will aid in having the Chevrolet Models dropdown appear as null or blank if "Chevrolet" is selected in the Make dropdown. menu field.

 

See slide:

 

vehiclemake-dropdowns.png

 

Note in the slide above that I have selected the blank entry as my first choice before closing the dialogue box. If you don't do this , when you reset this field, it will always default to whatever you had selected in it before you close the Properties dialoguw box.

 

 

For the script portion of this exercise, I am using the following  as custom calculation script in the "Make" dropdown menu field:

 

if (event.value == "Chevrolet") {

   this.getField("Chevrolet Models").display = display.visible;

   }

if (event.value !== "Chevrolet") {
   
   this.getField("Chevrolet Models").display = display.hidden;
   
   if (this.getField("Chevrolet Models").value !=="") {this.getField("Chevrolet Models").value =" ";}

// or you can use ---->>>>   this.resetForm(["Chevrolet Models"]);

 }


 

 

Note also that in the script that you've posted earlier there is a space before the word "display: 

 

  •  this.getField("Chevrolet Models") display 

 

It should be a single phrase connected by a period( ".") soon  after the prenthesis " ) " and before the word "display", like this:

 

  •  this.getField("Chevrolet Models").display 
  •  

 

 

TOPICS
How to, PDF forms

Views

89

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

Reset drop-down value to default when drop-down becomes hidden.

Community Beginner ,
Aug 23, 2020

Copy link to clipboard

Copied

Working with a few dropdowns, one is always visible and when a value is selected in it, another field  becomes visible. How can I tell the invisible dropdowns to return to a default value if they're invisible?

 

if (this.getField("Make").value == "Chevrolet") this.getField("Chevrolet Models") display = display.visible;

else if (this.getField("Make").value != "Chevrolet") this.getField("Chevrolet Models") display = display.hidden;

 

That's all I'm working with so far. It'll hide the field of course but if a value is selected in the newly visible field it will remain selected when the field is invisible. 

 

Halp plz!

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

First make sure that both dropdown menu fields are set to commit selected value immediately and disable to allow users to enter custom text.

 

Also add a space entry in the dropdown options lists. 

 

This is key in order to be able to use the "this.resetForm()" function or to use a condition  that will aid in having the Chevrolet Models dropdown appear as null or blank if "Chevrolet" is selected in the Make dropdown. menu field.

 

See slide:

 

vehiclemake-dropdowns.png

 

Note in the slide above that I have selected the blank entry as my first choice before closing the dialogue box. If you don't do this , when you reset this field, it will always default to whatever you had selected in it before you close the Properties dialoguw box.

 

 

For the script portion of this exercise, I am using the following  as custom calculation script in the "Make" dropdown menu field:

 

if (event.value == "Chevrolet") {

   this.getField("Chevrolet Models").display = display.visible;

   }

if (event.value !== "Chevrolet") {
   
   this.getField("Chevrolet Models").display = display.hidden;
   
   if (this.getField("Chevrolet Models").value !=="") {this.getField("Chevrolet Models").value =" ";}

// or you can use ---->>>>   this.resetForm(["Chevrolet Models"]);

 }


 

 

Note also that in the script that you've posted earlier there is a space before the word "display: 

 

  •  this.getField("Chevrolet Models") display 

 

It should be a single phrase connected by a period( ".") soon  after the prenthesis " ) " and before the word "display", like this:

 

  •  this.getField("Chevrolet Models").display 
  •  

 

 

TOPICS
How to, PDF forms

Views

90

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
Aug 23, 2020 0
Adobe Community Professional ,
Aug 23, 2020

Copy link to clipboard

Copied

First make sure that both dropdown menu fields are set to commit selected value immediately and disable to allow users to enter custom text.

 

Also add a space entry in the dropdown options lists. 

 

This is key in order to be able to use the "this.resetForm()" function or to use a condition  that will aid in having the Chevrolet Models dropdown appear as null or blank if "Chevrolet" is selected in the Make dropdown. menu field.

 

See slide:

 

vehiclemake-dropdowns.png

 

Note in the slide above that I have selected the blank entry as my first choice before closing the dialogue box. If you don't do this , when you reset this field, it will always default to whatever you had selected in it before you close the Properties dialoguw box.

 

 

For the script portion of this exercise, I am using the following  as custom calculation script in the "Make" dropdown menu field:

 

if (event.value == "Chevrolet") {

   this.getField("Chevrolet Models").display = display.visible;

   }

if (event.value !== "Chevrolet") {
   
   this.getField("Chevrolet Models").display = display.hidden;
   
   if (this.getField("Chevrolet Models").value !=="") {this.getField("Chevrolet Models").value =" ";}

// or you can use ---->>>>   this.resetForm(["Chevrolet Models"]);

 }


 

 

Note also that in the script that you've posted earlier there is a space before the word "display: 

 

  •  this.getField("Chevrolet Models") display 

 

It should be a single phrase connected by a period( ".") soon  after the prenthesis " ) " and before the word "display", like this:

 

  •  this.getField("Chevrolet Models").display 
  •  

 

 

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...
Aug 23, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

Small correction. It's not:

this.reset.Form(["Chevrolet Models"]);

But:

this.resetForm(["Chevrolet Models"]);

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...
Aug 24, 2020 0
Adobe Community Professional ,
Aug 24, 2020

Copy link to clipboard

Copied

Oooh! sorry about that I missed that typo. Thank you!

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...
Aug 24, 2020 0
Adobe Community Professional ,
Aug 24, 2020

Copy link to clipboard

Copied

I just fixed it.

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...
Aug 24, 2020 0
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

This worked prefectly! Thank you so much for your help!  I saw your note about the typo and went over the code very carefully to see if there were any other inconsistencies- found 2.

 

if (event.value == "Chevrolet") { this.getField("Chevrolet Models").display = display.visible; }
if (event.value !== "Chevrolet") { this.getField("Chevrolet Models").display = display.hidden; }
if (this.getField("Chevrolet Models").value !=="") { this.resetForm(["Chevrolet Models"]); }

I added a } at the end of the second if statement and a space between the last { and this.resetForm.  I'm still learning all this as I go so I have no idea if they're even relevant changes.

 

Thanks again! This solves a ton of current and anticipated headaches!

 

 

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...
Aug 24, 2020 1