Skip to main content
Known Participant
January 11, 2019
Answered

blank selection for dropdown

  • January 11, 2019
  • 3 replies
  • 13938 views

I have a drop down that is required. but I do not want to have a selection pre chosen. I want to see it empty when first opening the form.

but when I do that, it accepts the blank as a choice.

I want to set the field as required but and force user to make a choice.

Correct answer try67

Being new at JS still, I may have mis spoke. I am trying to learn ad do stuff on my own, but holy JS is not easy.

I need a script that will check 2 dropdowns to make sure a choice was made. There is a default of 'click for more options'.

So my script checks to see if click for more options was chosen, if so it generates an error message......but then still emails the form.

I need to get the email submit in the script, not sure how.

This is what I have. I tried using and AND/OR but it did not work.

if (this.getField("typeofestablishment").valueAsString=="click for more options") { 

         app.alert("Please select a valid Choice Number 5"); 

     }

else if (this.getField("typeoflossortheft").valueAsString=="click for more options")  {

app.alert("Please select a valid Choice Number 6");

}


Use this:

if (this.getField("typeofestablishment").valueAsString=="click for more options") {

    app.alert("Please select a valid Choice Number 5");

} else if (this.getField("typeoflossortheft").valueAsString=="click for more options")  {

    app.alert("Please select a valid Choice Number 6");

} else this.mailDoc({cTo: "me@server.com"});

3 replies

69butthead69
Participant
May 11, 2022

I know this is old, but I haven't seen anyone put the correct and easy way to do this anywhere. Putting it here in case anyone else runs into this issue.

 

After adding dropdown items in Item List, if you want the default to stay blank, simply click the white space under the different items in Item List. Done.

 

Hope this helps whoever runs into the same issue.

 

-69butthead69

Inspiring
May 11, 2022

And what when that list is filled with more then 7 items  and white space is gone, it will only work if you have like 1-6 items.

Participating Frequently
May 11, 2022

Command-click the selected dropdown item. It will become unselected, and the field will become blank.

Participant
May 30, 2020

May I ask where to put the JavaScript?

 

 

try67
Community Expert
Community Expert
May 30, 2020

As the Mouse Up event of your submit button.

Inspiring
January 11, 2019

If you use the UI then you enter a space. You can only add an empty or null string usong JavaSript.

murrjamesAuthor
Known Participant
January 11, 2019

UI, you meant the form field properties....I tried that and it accepts it. I do not want it to accept a blank.

How to do this, which is not clear

Uou can pnlu add an empty or null string usong JavaSript.

try67
Community Expert
Community Expert
January 11, 2019

You can add an empty string as the default value using a script, like this:

this.getField("Dropdown1").setItems(["", "Item 1", "Item 2", "Item 3"]);

I'm not sure if it will cause the required fields validation to fail, though, if that empty item is selected.

If it doesn't then you will also need to perform that validation using a script. I've posted similar scripts here in the past. Try searching for "validate required fields".