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

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

Community Beginner ,
Aug 23, 2020 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!

TOPICS
How to , PDF forms

Views

2.1K

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
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Aug 23, 2020 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 
  •  

 

 

View solution in original post

Votes

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
community guidelines
Community Expert ,
Aug 23, 2020 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 
  •  

 

 

Votes

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
community guidelines
Community Expert ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

Small correction. It's not:

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

But:

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

Votes

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
community guidelines
Community Expert ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

I just fixed it.

Votes

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
community guidelines
Community Beginner ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

LATEST

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!

 

 

Votes

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
community guidelines