Expand my Community achievements bar.

Using a List Box to Allow Multiple Selections to Populate a Text Field

Avatar

Level 1

Hi, I'm relatively new to Adobe LiveCycle Designer ES4 and writing javascript.  I'm having a hard time making my list box work and populate a text field.  

I want the user to be able to select multiple selections from the list box and those selections would populate in the text field.  Right now if the user selects an item from the list box and then selects another item from the list box, the previous selection is replaced by the new selection.

Here is the script I have.

form1.StatutesListBox::exit - (JavaScript, client)

if(this.rawValue=="2"){
SelectedStatutes.rawValue = "8 § 1324(a)(1)(A)(ii) Illegal transportation of an Alien";
}
if(this.rawValue=="3"){
SelectedStatutes.rawValue = "8 § 1326 Reentry of Deported Alien; Criminal penalties for reentry of certain Deported Aliens";
}
if(this.rawValue=="5"){
SelectedStatutes.rawValue = "18 § 2 Aiding and Abetting";
}
if(this.rawValue=="6"){
SelectedStatutes.rawValue = "18 § 4 Misprision of Felony";
}

 

Is there a way that I can have multiple items selected from the list box that will ALL populate in the text field?

 

Thanks for any help/advice you can provide.

1 Reply

Avatar

Level 10

This is quite easy to accomplish.

When you exit a lst field, it returns a list of strings that you can turn into an array which can be processed by a loop to get the results.

 

var aSel = this.rawValue.split("\n"), // create an array from the selections in the list field
	// a reference array with a sub array containing the possible selection and the corresponding string going to be returned
        aStrings = [
		["2", "8 § 1324(a)(1)(A)(ii) Illegal transportation of an Alien"],
		["3", "8 § 1326 Reentry of Deported Alien; Criminal penalties for reentry of certain Deported Aliens"],
		["5", "18 § 2 Aiding and Abetting"]
	],
	cResult = ""; // Empty result string

// Check every selection …
aSel.forEach(function (cSel) {
        // … against every string in the reference array
	aStrings.forEach(function (aString) {
		cResult += aString[0] === cSel ? aString[1].concat("\n") : "";
	});
});
Textfield.rawValue = cResult; // Write results into textfield

 

Hope this helps.