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

Need help with a custom format script for a dropdown menu

Community Beginner ,
Apr 24, 2024 Apr 24, 2024

Hi! I'm creating a purchase request form for my department. This form has a dropdown menu with different department accounts/numbers listed for them to choose from. On the dropdown, the text is formatted as-

 

[ACCOUNT #] - [ACCOUNT NAME] 

 

-and I have the account number as the export value. I currently have the below custom format script so that when the account number/name is selected, only the account number (listed as the export value) will populate:

 

event.value = event.target.getItemAt(event.target.currentValueIndices, true);

 

My problem is, that I also want to be able to insert custom text in addition to the dropdown options. When I currently try to enter custom text, it auto populates the closest account number listed in the dropdown, despite having the custom text option clicked. I understand this is likely due to the custom format script. Is there anything I can add to the script that will also allow custom text to be entered? 

 

Thanks!

TOPICS
JavaScript , PDF , PDF forms
649
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 ,
Apr 24, 2024 Apr 24, 2024

Use this code:

 

if (event.target.currentValueIndices>=0) event.value = event.target.getItemAt(event.target.currentValueIndices, true);

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 ,
Apr 24, 2024 Apr 24, 2024

Use this code:

 

if (event.target.currentValueIndices>=0) event.value = event.target.getItemAt(event.target.currentValueIndices, 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
Community Beginner ,
Apr 24, 2024 Apr 24, 2024

Thank you!! That works! 🙂 

 

One more question: 

 

Based on someone's choice on the Account # dropdown, another field will autopoplate with corresponding numbers for that account. This is the custom calculation script I have for that text box:

 

var v = this.getField("FUND").valueAsString;


if (v == "######") {
event.value = "######";

} else if (v == "######") {
event.value = "######";


} else {
event.value = "";
}

 

My issue with this is, I also would like for users to be able to enter custom text into this field as well, but currently it automatically makes any text entered blank. Any ideas?

 

Thanks!

 

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 ,
Apr 24, 2024 Apr 24, 2024
LATEST

Actually, nevermind, I think I was able to use the same code as my "else" on the text box as well!!

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