1
0
-1

Has anyone found a workaround to retain user-entered line breaks in text in a Multiline Text Area component in the PDF receipt?

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi Lin,

      Editing the Text Area content in Source mode works for me:

      Bill

      1. Lin VanOevelen

        I'm referring to the user entered data, not the label. If users type in line breaks in the data they enter, those get stripped out in the PDF so it all displays as one line.

        Like this: (this text had 7 line breaks when typed into the form)

        Ignore the text display. I returned the multiline data to it to see if that would work.

        And this is the form.html file, but that's how it displays in the PDF receipt.

      2. Unknown User (bfrost)

        Of course... silly of me...

        This works, in a Form Load rule:

        if (Util.isReceipt) {
          $('#multilineTextAreaEmbed').parent().html($('textarea').val().replace(/\n/g, '<br>'));
        }

        You might need to tweak the overall replacement html to retain class names for styling etc.

      3. Lin VanOevelen

        That works!

        But it doesn't show the field label in the receipt.

      4. Unknown User (bfrost)

        Hi Lin,

        I'm having more success with this:

        if (Util.isReceipt) {
          var ta = $('#multilineTextAreaEmbed').val().replace(/\n/g, '<br>');
          $('#multilineTextAreaEmbed').replaceWith(ta);
        }

        But there is an alignment issue I haven't been able to resolve yet.

        I'll be away for some time, so somebody else will probably follow up with your question.

        Bill


      5. Lin VanOevelen

        In the meantime, Matt here has been looking at your suggestion and played around with this too and he came up with this:

        if (Util.isReceipt) {
        var fixNewLines = function (id) {
        var el = $('#' + id);
        var fielddata = el.val().replace(/\n/g, '<br>')
        el.replaceWith('<p>' + fielddata + '</p>')
        }
        
        fixNewLines('test_1')
        fixNewLines('test_2')
        }

        It's very hacky, but it seems to work.

      6. Matthew White

        I'm pretty sure that using query's html method is insecure as it will execute embedded script tags and running this on the server inside a receipt would be problematic. Is there a safer alternative?

      CommentAdd your comment...