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

Validate Dropdown selections

New Here ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Hey everyone,

I am most certain this is a simple if statement, but since my java knowledge is pretty outdated, I need some help. I am creating an interactive pdf and I need to validate the form. I am using dropdown menus for the most part and I need a script to check to see if the default selection is still present. If so, I need a prompt to highlight  the dropdown menu that still has the default value present.  Can anyone help?

Thanks!

- G

TOPICS
Acrobat SDK and JavaScript , Windows

Views

3.6K

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 ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

You can use this code to do that:

var f = this.getField("Dropdown1");

if (f.valueAsString==f.defaultValue) {

    app.alert("You must fill in this field before submitting the file.",1);

    f.setFocus();

} else this.mailDoc();

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
New Here ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

For some reason, this is not working. I just tested it and left one of the dropdown selections with the default value and no prompt or error code populates. I have attached this code within a button.

Thanks!

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 ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

You can't attach PDF files here. You should upload it to a sharing website like Dropbox or Google Drive and then post the link to 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
New Here ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

I did not attach anything in here. My apologies if I was not clear. I meant to say that I attached your code with the correct name of my dropdown menu within a button and not directly in the dropdown. Sorry if this is unclear.

Thanks!

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 ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

So what happens when you click the button, exactly? Are there any error messages in the JS Console (Ctrl+J)?

Can you share the actual file?

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
New Here ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

I can not share the actual file (internal use only), nothing happens when I select the button with the code, no error messages or anything.

- G

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 ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Then create a file with just the drop-down field (you can replace the values with dummy ones) and the submit button and share that... Otherwise it's very hard to help 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
New Here ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Ok, so I just got it to work! Which is great, thank you! But it doesn't highlight the dropdown that is causing the prompt. I have the java included in the submit but a step before the email submission. Also, how you make the script validate multiple drop down menus or do I have to use a separate line of script to call out each DD?

I have included a sample doc.

dropdown-validation-mockup-interactive.pdf - Google Drive

THANK YOU once again!

- G

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 ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

You need to delete the "Submit form" command and leave only the Run a JavaScript command. The script takes care of submitting the form, and will abort it if the field is not filed-in. If you do that you will also see that the script causes that field to become selected, so it's obvious to the user which field is referred to.

Regarding performing this for multiple fields: It can be done using a more generic script.

You would need to set those fields as "required" and then use a script to iterate over all of the fields in the file, checking that the required ones among them are actually filled in. I've posted several codes that do that over the years on these forums. Try searching for "required fields validation" and I'll sure you'll find 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
New Here ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

I am trying to use the script below based on the comments above, but I'm also needing to get it to work for multiple fields. I would like it to work for fields named Facility, Title, Type, Hours, Shift, and Matrix. All are dropdown fields with the default value as a blank spacebar, but I want the users to have to select an actual value in all of those fields before the submit email opens. I'm having trouble finding a script you've done for multiple dropdown fields -- I've found them for blank text fields, but since the dropdown isn't technically blank, that's where I'm struggling. I'm hoping you could point me in the right direction? Sorry, this answer has been the closest I could find, and it's my first time using javascript. 

 

var f = this.getField("Facility");

 

if (f.valueAsString==f.defaultValue) {

 

    app.alert("You must fill in all required fields before submitting the file.",1);

 

    f.setFocus();

 

} else this.mailDoc({

    cTo: "",

    cSubject: "Vacancy Notice",

    cMsg: "Please see the vacancy notice form attached."

});

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

LATEST

If you want to send an email that validates fields before sending then I would suggest using a button script. Put the word "Send" on the button. Then acquire all the required fields and test them.

 

You can read about document/form level validation here:

https://www.pdfscripting.com/public/Form-Data-Validation.cfm

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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