Expand my Community achievements bar.

SOLVED

Populate Text Box with mulitple selctions from list box

Avatar

Level 2

Hello,

I am new to LiveCycle and searched the forums for an answer as to how to populate multiple selections from a list box to a text field.

I added to the calculate field of the text field the following: TextField14.rawValue = ListBox1.rawValue

Is there a way I can modify this so that the items from the listbox populate the text field so that the values show up side by side (i.e. California, Connecticut, New York) instead of top-down?

Joe

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I would use the following JS code in the 'exit' event of the List box

var

ListValue = this.rawValue;

ListValue

= replaceAll(ListValue, "\n", " ,");

TextField1.rawValue

= ListValue;

function

replaceAll(oldStr,findStr, repStr) {

     var srchNdx = 0; // srchNdx will keep track of where in the whole line

     // of oldStr are we searching.

     var newStr = ""; // newStr will hold the altered version of oldStr.

     while (oldStr.indexOf(findStr,srchNdx) != -1)

          // As long as there are strings to replace, this loop

          // will run.

          {

          newStr

+= oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));

          // Put it all the unaltered text from one findStr to

          // the next findStr into newStr.

          newStr

+= repStr;

          // Instead of putting the old string, put in the

          // new string instead.

          srchNdx

= (oldStr.indexOf(findStr,srchNdx) + findStr.length);

          // Now jump to the next chunk of text till the next findStr.

          }

     newStr

+= oldStr.substring(srchNdx,oldStr.length);

     // Put whatever's left into newStr.

     return newStr;

}

Good Luck,

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

I would use the following JS code in the 'exit' event of the List box

var

ListValue = this.rawValue;

ListValue

= replaceAll(ListValue, "\n", " ,");

TextField1.rawValue

= ListValue;

function

replaceAll(oldStr,findStr, repStr) {

     var srchNdx = 0; // srchNdx will keep track of where in the whole line

     // of oldStr are we searching.

     var newStr = ""; // newStr will hold the altered version of oldStr.

     while (oldStr.indexOf(findStr,srchNdx) != -1)

          // As long as there are strings to replace, this loop

          // will run.

          {

          newStr

+= oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));

          // Put it all the unaltered text from one findStr to

          // the next findStr into newStr.

          newStr

+= repStr;

          // Instead of putting the old string, put in the

          // new string instead.

          srchNdx

= (oldStr.indexOf(findStr,srchNdx) + findStr.length);

          // Now jump to the next chunk of text till the next findStr.

          }

     newStr

+= oldStr.substring(srchNdx,oldStr.length);

     // Put whatever's left into newStr.

     return newStr;

}

Good Luck,

Avatar

Level 2

Thanks, I'll give that a try.

Joe

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----