Copy link to clipboard
Copied
Hello,
I have a dropdown (Reasons) with multiple selections (Test1, Test2, Test3). I want to be able to select one option (Test1), have that value populate a text field (ReasonsList), return to a new line or have a comma, and then populate another value when I select another option (selecting Test2 after Test1 would give me "Test1, Test2" in the text field).
Is this possible? I've found some Javascript in other community posts, but I'm not able to get it to work for my case.
As the custom Validation script of the drop-down enter the following code:
if (event.value) {
var reasonsListField = this.getField("ReasonsList");
if (reasonsListField.valueAsString=="") reasonsListField.value = event.value;
else reasonsListField.value+=", " + event.value;
}
Make sure to tick the option to commit the selected value of the drop-down automatically if you want the text field's value to update as soon as you make a selection. Otherwise it will only work when you exit the
...There is an error in last line: else reasonsListField.value+=", " + event.value;
Copy link to clipboard
Copied
As the custom Validation script of the drop-down enter the following code:
if (event.value) {
var reasonsListField = this.getField("ReasonsList");
if (reasonsListField.valueAsString=="") reasonsListField.value = event.value;
else reasonsListField.value+=", " + event.value;
}
Make sure to tick the option to commit the selected value of the drop-down automatically if you want the text field's value to update as soon as you make a selection. Otherwise it will only work when you exit the drop-down field.
[Edited: Code fixed]
Copy link to clipboard
Copied
Thank you for the quick response. This handles the first part where it throws the value into the text field. Is it possible then to add a line break or comma, followed by a second selection value if I were to then click on "Test2" in the dropdown?
Copy link to clipboard
Copied
There is an error in last line: else reasonsListField.value+=", " + event.value;
Copy link to clipboard
Copied
Thank you both for the responses. It looks like it's doing what I need it to. \o/
Copy link to clipboard
Copied
If you don't want to allow duplicates, here is a modified script:
if (event.value) {
var reasonsListField = this.getField("ReasonsList");
if (reasonsListField.valueAsString == "") {
reasonsListField.value = event.value;}
else {
var currentValues = reasonsListField.value.split(", ");
if (currentValues.indexOf(event.value) == -1) {
reasonsListField.value += ", " + event.value;}}}
Copy link to clipboard
Copied
Good catch! I fixed it now.