Skip to main content
Participant
April 24, 2024
Answered

Need help with a custom format script for a dropdown menu

  • April 24, 2024
  • 1 reply
  • 832 views

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!

This topic has been closed for replies.
Correct answer try67

Use this code:

 

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

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 24, 2024

Use this code:

 

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

Participant
April 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!

 

Participant
April 24, 2024

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