1

Right now, when you press enter in the text field it causes a carriage return. You can then type on the next line. But, when you press the button to submit the text, the result gives no spacing between the characters found on the separate lines. How do I code for the <br> or the \n to occur on submit? For example, when I type:
test
test
It returns:
testtest
Here's the code...

Ossn.PostComment = function($container) {
    $('#comment-box-' + $container).keypress(function(e) {
        if (e.which == 13) {
            if (e.shiftKey === true) {
                //Postings and comments with same behaviour #924
                $replace_tags = function(input, allowed) {
                    allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('')
                    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi
                    var commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>|&nbsp;/gi
                    return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) {
                        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''
                    })
                };

                $text = $('#comment-box-' + $container).html();
                $text = $replace_tags($text, '<br>').replace(/<br ?\/?>/g, "\n");
                $('#comment-container-' + $container).append("<textarea name='comment' class='hidden'>" + $text + "</textarea>");
                $('#comment-container-' + $container).submit();
            }
        }
    });
  • this coding provides one breaking space on enter... $text = $replace_tags($text, '
    ').replace(/\
    /g, "
    "); $text = $replace_tags($text, '
    ').replace(/\<\/div\\?>/g, "
    "); $text = $replace_tags($text, '
    ').replace(/\
    /g, '\n'); ... so we end up with "test test"
    – Allon Prooit May 07 '20 at 22:32
  • pardon... it now gives one non-breaking page space on submit. – Allon Prooit May 07 '20 at 22:40

0 Answers0