0 Replies Latest reply on Feb 6, 2015 8:45 AM by BSisson

    ListBox Structure doing weird things to Script for multi-line text boxes...

    BSisson Level 1

      Ok...I am trying to build a "Smart" listbox/multi-line textbox wrap thing...

       

      How it WORKS in another module where I used the code is:

      the String comes in (f) and I check it's length (.length) if it is less than my text box is long I stuff it into the textbox pointed to by position (text.position) and am done.

      If the String comes in LONG, I find the first space near the max length, and stuff everything UPTO that point into the text.position box, increment the line (position) and put the REMAINDER of the line back into (f) and do it again...  THIS WORKS very nicely...the result is what LOOKS like a smart multi-line text wrapping box.

       

      HOWEVER....

       

      When the Input is a LISTBOX export data, I get all sorts of weird errors...  I tried putting a structure in-between so that I am not trying to manipulate the Listbox, but a copy of it's export data...

      As soon as I get one error to go away, another shows up...

       

      HELP !!

       

      The following Script is in the list boxes' "Selection Change".  My Listbox is called CannedComments and the text boxes are Text1, Text2 and Text3.  this code has lots of console prints in it as debug...

       

      A working setup is at: Multiple select & Add.pdf - Google Drive

       

      The top box adds things to the list when the button is pressed  - that works... but the box won't clear afterword's... that's a different issues...

       

       

      //console.clear()
      {
      //  -----------This section clear the old Notes--------------------
      for (var loop = 1; loop <= 3; loop+=1)
       {                                                           //Loop through Summary to clear old entries
        var s = this.getField("Text"+loop);                        //get handle for Summary field
        console.println(" clearing loop "+loop)
        s.value = " ";                                             //clear it.
        }
      //  -----------End of Clear Notes
          var temp = this.getField("CannedComments");                 //get handle for lstBox
          var f = temp;                                              //can't manipulate the listbox, need a temp
          var position = 1;                                          //start at first text line
          console.println(" Incomming f: "+f.value);
          console.println(" Incomming line length :"+f.valueAsString.length);
             while(f.valueAsString.length > 20)
              {
                  var s = this.getField("Text"+position);                        //get handle for Summary field
                  console.println(" Incomming inside do/while f: "+f.value);
                  var firstspace = f.valueAsString.indexOf (" ",20);          // find first space after 20 char
                  var firstpart = f.valueAsString.slice(0,firstspace);        //this line upto the first space after 20 char
                  var leftover  = f.valueAsString.slice(firstspace);          //this is the remainder.
                  s.value = firstpart;
                  position += 1;
                  f.value =leftover;
                  console.println(" firstspace ="+firstspace+"  Leftover "+leftover);
              }
            console.println(" Exiting while ");
            var s = this.getField("Text"+position);
            s.value = f.value;
      
      
      

           
      }