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

Populate dropdown field options from other form fields in document

Community Beginner ,
Nov 04, 2022 Nov 04, 2022

Hi, I've scoured other threads but couldn't quite see the answer for what I'm looking for! Hoping someone can help. Apologies if this has been discussed before.

I'm creating a dropdown field where I want x2 dropdown options to be populated from x2 text fields within the document. I can only see the option to manually enter options to display rather than call on other fields to populate these options — can this be done?  Ideally I'd like to name these as Option 1/Option 2 from the dropdown selection but it's okay if these appear as what's written in the text boxes.

I'm assuming some sort of script may be needed to implement? Any help would be greatly appreciated!

I've attached a screengrab of what I'm hoping to achieve if that's useful for guidance.


TOPICS
Create PDFs , PDF forms
8.7K
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 07, 2022 Nov 07, 2022

I think you want something else, please test this file and see if that's what you need:

https://drive.google.com/file/d/1nWuCg1Fg6ZM45K1K6EPshZK56HVWF-cc/view?usp=share_link 

View solution in original post

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 ,
Nov 04, 2022 Nov 04, 2022

You can configure dropdown controls via JavaScript. You could write a script that monitors the form for changes in the relevant fields and then sets new options for the dropdown control. The Field.setItems() function will do that for you: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#setitems

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Thank you Karl for your reply. I'm still having trouble with this, I know close to nothing about JS so I know I'm doing something wrong!

I've used the below but this isn't pulling the fields, it's just taking the name of the fields than the content of them. Can you advise? Thanking you in advance!

var l = this.getField("Season Dropdown"); l.setItems(["Date 1", "Date 2"]);

My Dropdown box is called Season Dropdown, and the x2 dropdowns under the options tab are labelled as Option 1 and Option 2

The first field is labelled Date 1 which I want to appear as Option 1 in the Season Dropdown and the second field is labelled Date 2 which I want to pull through as Option 2

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 ,
Nov 04, 2022 Nov 04, 2022

Hi beth,

 

++Adding to Karl's always valuable guidance,

 

I just posted an example for another user 10 hours ago, which illustrates an simple example employing the method suggested by Karl.

 

If you're new to Acrobat JavaScript, the API Reference is an excellent choice to get famimiliarized with many methods.

 

Be advised, that I am still learning Acrobat JavaScript, but in the link below is the example script, which you may use and adapt to your workflow:

 

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Thank you ls_rbls for your reply. Sadly that doesn't seem to have worked for me (I'm not a JS person at all so I know I've probably gone wrong somewhere! But don't know where!)

My Dropdown box is called Season Dropdown, and the x2 dropdowns under the options tab are labelled as Option 1 and Option 2

The first field is labelled Date 1 which I want to appear as Option 1 in the Season Dropdown and the second field is labelled Date 2 which I want to pull through as Option 2

It won't let me enter this, I'm missing something but I'm not sure if the forumla is even right!? Thanking you in advance!

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 ,
Nov 07, 2022 Nov 07, 2022

Your code contains syntax errors, which is why it's not accepting it.

In the future, post your code as text, not as an image, please.

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Apologies, it wouldn't let me post the code becuase of the errors, hence the image! But I don't know where those errors are ðŸ˜…

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

I just get this message and it removed bits from the code so I thought an image would be helpful.

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 ,
Nov 07, 2022 Nov 07, 2022

That's strange, it should allow you to post it...

Anyway, after the getField command you can't just leave a dangling period. You must follow the example given above very carefully. Only change the strings to the names of your fields and the items you want to check or apply, do not change anything else about the syntax if you don't know what you're doing.

 

What are you trying to achieve there, exactly?

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

I thought it strange too, sorry not trying to be difficult ðŸ˜…

I've edited this now to read as below but it's still not working for me. Essentially I have 2 date fields that I would like to populate as the x2 options in a dropdown field as option 1 and option 2. I'm not 100% sure what I'm looking at to spot where I've gone wrong so any guidance is greatly appreciated.

if(event.willCommit)
{ if(event.value =="Option 1") { this.getField("Date 1").setItems(["<Option 1>",]);
} else {
if(event.value =="Option 2") { this.getField("Date 2").setItems(["<Option 2>", ])

}
}
}

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 ,
Nov 07, 2022 Nov 07, 2022

Remove the dangling commas after the strings in setItems.

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Like so? This sadly still isn't working for me. Am I right to be adding this JS under the Format tab > Custom Keystroke Script ? I've tried in both fields to check.

if(event.willCommit)
{ if(event.value =="Option 1") { this.getField("Date 1").setItems(["<Option 1>"]);
} else {
if(event.value =="Option 2") { this.getField("Date 2").setItems(["<Option 2>"])

}
}
}




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 ,
Nov 07, 2022 Nov 07, 2022

Yes, that code is fine. And yes, that event will work. What do you mean by "both fields", though? This should go under the first drop-down only. If it's not working check the JS Console for error messages.

If you still can't figure it out share the file with us for further help.

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Sorry, under the Format tab there's 2 fields to choose from where to post the JS "Custom Format Script" or "Custom Keystroke Script". I've tried it in both of these fields.

I've popped the fields in a new doc (identical to how they're labelled in my file – I can't post this due to confidentially). Sorry it's probably a really simple thing but due to my lack of knowledge I'm missing the obvious ðŸ˜… Thank you in advance.


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 ,
Nov 07, 2022 Nov 07, 2022

I think you want something else, please test this file and see if that's what you need:

https://drive.google.com/file/d/1nWuCg1Fg6ZM45K1K6EPshZK56HVWF-cc/view?usp=share_link 

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Nesa, this is exactly what I'm after. Thank you! How do I implement this?

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 ,
Nov 07, 2022 Nov 07, 2022

The date fields are not drop-downs, so using setItems on them will not work.
If you want to set their values do so like this, for example:

this.getField("Date 1").value = "27 Nov 2022";

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

@try67 sorry if I wasn't clear before. I want the drop down items to autopopulate whatever those date fields are set as to appear as the dropdown options. As @Nesa Nurani has shown in her example is what I'm hoping to achieve. Just need some guidance how to match this, I can see some script in the "validate" tab on the date fields but not sure how this pulls through to my dropdown, I'm still just seeing 'Select' / 'Option 1' / 'Option 2'

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 ,
Nov 07, 2022 Nov 07, 2022

If you copy scripts to your file, make sure field names are correct and remove old script if you had any.

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

Hi Nesa, I've copied the scripts over to the x2 date fields resepctively but I'm still just seeing these for my dropdowns, it hasn't autopopulated the dates as it did on your example?


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 ,
Nov 07, 2022 Nov 07, 2022

Post that file please.

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 Beginner ,
Nov 07, 2022 Nov 07, 2022

@Nesa Nurani I tried closing and reopening the PDF and that seems to have solved it ðŸ˜€ thank you so much for your help, and to everyone else who contributed. Very much appreciated!

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 ,
Nov 07, 2022 Nov 07, 2022

Beth, I know I am bit late to the party, but in the very beginning you said that you don't have any experience with JavaScript. If this is something you might do more often, you may want to invest some time to lear at least the basics of the language. There are  a lot of things in PDF forms that can benefit from a script or two (as you've just seen). A while ago, I wrote up some infomration about how to approach learning to program in JavaScript for Acrobat: http://khkonsulting.com/2017/01/learning-to-program-javascript-for-adobe-acrobat/

 

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 Beginner ,
Nov 07, 2022 Nov 07, 2022
LATEST

Hi @Karl Heinz Kremer thank you so much for this. I'm a graphic designer by trade so JS really is quite alien to me (I know the bits I need to know to acheive certain things!) but I agree it's super helpful to have an understanding to know what can and cannot be done in Acrobat. I will definitely check out your link ðŸ˜€

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