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

How do I make a required dropdown field option not a valid selection

Explorer ,
Dec 22, 2021 Dec 22, 2021

Sorry if this is a amature question. I am new to the Javascript "Validate Script" side of Adobe Acrobat Pro
How do I make a required Dropdown field option not a valid selection using Validate script. I have 4 Options Under Dropdown:

  1. Select One (Not a valid choice)-Want to use it as a default "Title"
  2. Option 1- (Valid Required Choice)
  3. Option 2- (Valid Required Choice)
  4. Option 3- (Valid Required Choice)

As it stands now "Select One" can be used as a choice and user can move on with out actually selecting one.

Is this a possible thing?

Ive searched all over and even tried to modify other scripts from post to try and accomplish this with zero success. 

Other post I was looking at: See Post Here

Script peices is credit to: try76 

(This is what I copied off it to try and accomplish my goal, as the full one seem unnessisary to my useage)

var f1 = this.getField("Option 1");
var f2 = this.getField("Option 2");
var f3 = this.getField("Option 3");
if (event.value=="Select One") {
    f1.readonly = true;
    f2.readonly = true;
    f3.readonly = true;
    f1.required = false;
    f2.required = false;
    f3.required = false;
}

 

Thanks for any help. 

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms
5.9K
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
Community Expert ,
Dec 22, 2021 Dec 22, 2021

Want you that the user can't select one of the options?

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
Explorer ,
Dec 22, 2021 Dec 22, 2021

I want to make the 3 options the only options they can choose as a requirement. So if they select option 1, option 2, or option 3 from the dropdown, they can move on. But if they select "Select One" that's disabled and doesn't count as one of the  required choices and can't. Because it's just a instruction or title if you will.

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
Community Expert ,
Dec 22, 2021 Dec 22, 2021

You can set so field is required if "Select One" is selected and if any other choice is selected field is not required, but you will need to use 'Calculation script' for that:

event.target.required = event.value == "Select One" ? true : false;

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Thank you Nesa. I feel like thats closer. It highlights "Select One" with a red box and when the other 3 options are picked it doesn't have a red box. Isnt it suppose to shoot a message or something? I can still pass it up and ignore it basically. 

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Use this:

event.target.required = event.value == "Select One" ? false : true;

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Thank you Bernd. That's not quite it. The other way is closer. It just doesn't give any kind of warning or message to let the user know they missed making a selection. I do like how it shows the red box around the "Select One" and then they make it disappear by make a selection of one of the 3 options. But if they pass it up it doesn't do nothing. Kinda like the date or phone number field if it's in the wrong format or to many numbers it gives you a pop up. Is that something that can be done if they try to pass it with out making a selection?

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Red box means the field is required (which you said you want) when you submit form if field is required it will pop a message. But I'm guessing you don't actualy submit form?

If you just want alert msg you can use app.alert("custom message goes here") but you will need to figure out what will be a trigger for alert.

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Yeah, thats correct. It wont be submitted. Thanks for pointing it out. Didnt even think of that. 
So I guess my question is now. How do I run a a trigger when it comes to passing it up going to the next field by pressing enter. or if there is another way I don't know about. 

So far I have.. under actions mouse and it just pops the message up when ever I get near it. 

if (event.target.value == "Select One")
    app.alert("Please Select One of the Options");

 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

is there a way to gray out "Select One" and it not be a selection? but just show in the box. Kind of like if you go to a contact form and say for example the Email field has the light gray "Email" Or "Your Email" labeling that's what goes there. Then do the required thing. Just trying to figure out my options.  

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Yes, but you would need to have 'blank' (space character) as option instead of 'Select One', then as 'Custom format script' you can use something like this:

if(event.value == " "){
event.value = "Select One";
event.target.textColor = color.gray;}
else event.target.textColor = color.black;

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Perfect I like that a lot better visually. But now my required (red box) disappeared. 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

wait nvm had to change the first script took out the "Select One" part and put a space. think ill do with out the message box if I cant figure out the enter button thing. the mouse getting near it pop up is kind of a pain and annoying. 

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

If you have next field in line put alert there so they go back to previous field and make choice.

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Ah gotcha. So it would be the

if (event.target.value == "Select One")
    app.alert("Please Select One of the Options Under Waiver Type");

 would the mouse Enter trigger work best? 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

yeah that trigger isnt working lol *face palm*

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

If you are using script in another field you need to make script reference to dropdown field, just change 'event.target.value' to 'this.getField("Dropdown").valueAsString;' (change 'Dropdown' to your actual dropdown field name).

Use script as 'Mouse UP' not 'Mouse Enter'.

 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

So like this? 

if (this.getField(" ").valueAsString;)
    app.alert("Please Select One of the Options Under Waiver Type");

 Because its for the blank option on the drop down, if they skip it. I assume Im working with the zip code now for the warning.  

Untitled-1.jpg

 

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Yes, you can use zip code field for alert, but use waiver field name in script.

Use it like this:

if (this.getField("Waiver type field name goes here").valueAsString == " ")
app.alert("Please Select One of the Options Under Waiver Type");

 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Perfect! Thanks so much! I assume this is the exstent of possibilities with what I'm trying to do when it comes to "clicking" the next field aka zip code and pressing "enter" to go to the next field.

 

Also no way to change the warning box to be smaller or even the ugly title. Warning: JavaScript Window

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Not sure I understand, you want to go to next field when press "enter"?

Warning box shouldn't be too big, I'm guessing it's related to screen resolution.

Warning: JavaScript Window can be removed by making document trusted but it wouldn't work for other users, you can read about trust methods here .

 

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
Explorer ,
Dec 24, 2021 Dec 24, 2021

Thank you. Its not that big of deal to get into all that lol. 

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
Explorer ,
Dec 23, 2021 Dec 23, 2021

Ran into a slight issue when I tested it more. Warning still pops up When "Waiver Type" isn't required per selection in "Coverage Type".
Only was able to get this script to work if I changed the Orange writing to "Dropdown7.0" vs one of the drop down options:

" " -blank title option

"Spousal-S"

"Individual-I"

"None-N"

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
Community Expert ,
Dec 23, 2021 Dec 23, 2021

Yes, orange writing is where the field name goes.

If requirement also depends on "Coverage Type" you need to add that condition to script also.

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
Explorer ,
Dec 24, 2021 Dec 24, 2021
LATEST

Yeah, is there a spot somewhere with these script commands. I cant figure it out. This is what I got, but don't understand. I know it wrong wont do anything but still displays a warning message

if (this.getField("Dropdown7.0").valueAsString == " ")
app.alert("Please Select One of the Options Under Waiver Type");

else if (this.getField("Dropdown7.0").valueAsString == "")
{
(this.getField("Dropdown7.0").required = false);
}

 

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