Copy link to clipboard
Copied
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:
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.
Copy link to clipboard
Copied
Want you that the user can't select one of the options?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Use this:
event.target.required = event.value == "Select One" ? false : true;
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Perfect I like that a lot better visually. But now my required (red box) disappeared.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
If you have next field in line put alert there so they go back to previous field and make choice.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
yeah that trigger isnt working lol *face palm*
Copy link to clipboard
Copied
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'.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 .
Copy link to clipboard
Copied
Thank you. Its not that big of deal to get into all that lol.
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more