• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

New Line character in Text Area

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New Line character in Text Area

    I have a form which contains editable text field in Text Area format
    I have to populate this field when I open this form.
    For this, I read a file and I concat the field into one field. I use SetResponse for showing this on form.
    dow not %eof
    txtDPODesc = %trim(txtDPODesc) + %trim(DESCRIPTION);
    reade file;
    enddo
    SetResponse('formFieldValue':'XXPDDESC' :%trim(txtDPODesc));

    Now the thing is, I need to show each description on new line of the text area(as shown below).
    I tried using <br>, \n but that doesn’t work. What should I use.

    Also, user can update this field, and they can enter multiple lines of description, and I want to separate each new line and insert as independent record.
    So, what should I use for scanning the new line character.

    dataurl259706.png
    ?

  • #2
    When the Enter key is pressed in a textarea, it uses the newline character \n. This newline character is included in the value sent to the backend.

    We found a bug that occurs when a template program or app variable sets the value of the textarea with newline characters due to encoding issues. This will be fixed in the next 6.3 update, which should be released by mid next week.

    Once the update is released and applied, you can set the value of the textarea to, for example, 'row1\nrow2\nrow3', and the textarea will display:?
    Code:
    row1
    row2
    row3
    If you do not want to wait for the 6.3 update, you could add an Execute Script to the startup of your application that will patch the setting of the textarea with newlines, as shown below:
    Code:
    const myForm = getWidget('myForm'); // form with textareas
    const textAreas = myForm.query('textarea'); // get the textareas
    
    textAreas.forEach(function(fld) {
        const originalSetValue = fld.setValue.bind(fld);
    
        fld.setValue = function(value) {
            if (!Valence.isEmpty(value) && Valence.isString(value)) {
                value = value.replace(/\\n/g, '\n');
            }
            return originalSetValue(value);
        }
    });
    
    success();

    Comment


    • #3
      Is this fix included in 6.3.20241120 release

      Comment


      • #4
        This update should be included in 6.3.20241120.2

        Comment


        • #5
          The loading of new line character from Program to Form is working fine,
          But, I am still facing the issue while reading the new line character in program. I want to identify the new line character and break the text into new field.

          Refer attached screen shots.

          Description on Form
          image.png?

          What is see in Program
          ??
          txtDPODesc = GetFormChar('XXPDDESC');

          image.png

          I use below command to identify it but its not working.
          WHEN %scan('\n':txtDPODesc) > 0;
          ??

          Comment


          • #6
            Look at the hex representation of that in debug... I think you'll find a linefeed (x'25') where you see the reverse image blocks. That's what you need to scan for.

            Comment


            • #7
              This is working, Thanks.

              Comment

              Working...
              X