Copy link to clipboard
Copied
Hello, is it possible to have a button in a form that when clicked, you can add/delete an option in your dropdown list? (instead of going to options of a dropdown list). can you give me example of a script if possible. Thanks!
Expected Output:
Type input in text field > Pressing the Add button Will Add the input in dropdown list
Use like this:
var drop = this.getField("Dropdown5");
var str = this.getField("text4").valueAsString;
drop.insertItemAt(str,"", 0);
Ok, first there was an error in my script above, it's fixed now so use new script.
To sort items, you can use the correct answer from this post:
https://answers.acrobatusers.com/Alphabetic-order-drop-list-q255525.aspx
When you add document level script, add this line to the script I posted above:
ListEntrySort(drop.name);
Script in button should look like this:
var drop = this.getField("Dropdown5");
var str = this.getField("text4").valueAsString;
drop.insertItemAt(str,"", 0);
ListEntrySort(dro
...
Copy link to clipboard
Copied
You can use insertItemAt() to add item to dropdown and deleteItemAt() to delete item from dropdown.
0 = first item in the list.
-1 = last item in the list.
Example of adding item to top of the list:
var drop = this.getField("Dropdown");
drop.insertItemAt("Orange", 0);
Same for deleting item, if no number is set it will delete the currently selected item.
Example of deleting currently selected item, then select the top item in the list:
var drop = this.getField("Dropdown");
drop.deleteItemAt();
drop.currentValueIndices = 0;
Copy link to clipboard
Copied
thank you,
can you see if this is right (this is the output I want) I tried the script but I always got error
btw this is my expected output
Copy link to clipboard
Copied
Yes, you can add text field value to dropdown via button.
Post script you tried.
Copy link to clipboard
Copied
I typed 'Try' instead of it showing in the dropdownlist. It shows 'text4' which is the name of the text field.
Copy link to clipboard
Copied
Use like this:
var drop = this.getField("Dropdown5");
var str = this.getField("text4").valueAsString;
drop.insertItemAt(str,"", 0);
Copy link to clipboard
Copied
thank you! it worked
Copy link to clipboard
Copied
hi 😅 can I follow up one last question, what if I wanted the dropdown list to be sorted (Alphabetically) after adding new item in the list what should I change/do?
Copy link to clipboard
Copied
Ok, first there was an error in my script above, it's fixed now so use new script.
To sort items, you can use the correct answer from this post:
https://answers.acrobatusers.com/Alphabetic-order-drop-list-q255525.aspx
When you add document level script, add this line to the script I posted above:
ListEntrySort(drop.name);
Script in button should look like this:
var drop = this.getField("Dropdown5");
var str = this.getField("text4").valueAsString;
drop.insertItemAt(str,"", 0);
ListEntrySort(drop.name);
Copy link to clipboard
Copied
Just tick the option under the field's Properties to have it be sorted automatically:
Copy link to clipboard
Copied
@try67 unfortunately, that doesn't work when you add item via button (at least doesn't work for me, or I'm missing something).
If you go to options items are sorted but when using dropdown items are not sorted.
Copy link to clipboard
Copied
You're right, it doesn't sort it automatically, and unfortunately this setting is not settable using a script, so it can't be cleared and then re-set. So the only solution is to read the list of current items into an array, add the new item to it, sort that array and then re-apply it using setItems.
Copy link to clipboard
Copied
tnx tnx
Copy link to clipboard
Copied
Hi Nesa; I have a similar situation but different in that I would like to delete all the options except the one selected, and also delete all export values by pressing button before requesting signatures. Right now I'm having to do this in prefill stage of sign process. Thanks in advance- kemper
Copy link to clipboard
Copied