The implementation of <Textarea> doesn't handle CRs

PlatformIO’s implementation of the HTML for Textboxes - specifically < TEXTAREA > does not allow the use of CarriageReturns. If a Carriage Return is sent to a webpage’s TEXTAREA then the whole output isn’t displayed.

Having checked it with W3SCHOOLS website - other implementations of TEXTAREA handle CarriageReturns as expected.

When trying to format information to be presented to the user of a webpage - Carriage Returns are almost essential - as otherwise you have to pad out the string with extra spaces so that the new sentence starts on a new line and the number of spaces to be added is only applicable to the specific size of the TextArea - change that and the number of extra spaces would have to change - so it is difficult to work with.

Probably an easy fix - I would try if I could find it …

Where can that be observed? I’m a bit lost here.

Sorry - my explanation must have been too succint.

On an ESP8266 board - When you create a TextArea on a webpage - and then try and write text to it to be displayed in the textbox using ESPAsyncWebServer. You can write normal text to it - but when you try and enclose a CarriageReturn - by using an “\n” or by using Char(13) or the Char(10) ( as below ) the output disappears.

string2 = “Fred " ;
string2 += char(10) ;
string2 += char(13) ;
string2 += " < /br > GEORGE HELLO” ;
JSONtxt = “{"MsgToWeb":"” ; JSONtxt +=string2 ; JSONtxt += “"}”;
ws.textAll(JSONtxt.c_str()) ;

As you can see I tried a few variants - for example as expected < br > is just typed out to the TextArea unchanged.

Hope that give you enough to understand the issue - thanks

Have you checked what bytes the websocket received on the client side, in hex?

Also javascript - How do I handle newlines in JSON? - Stack Overflow says in JSON you would not use the \n character (code 0x0A / 10) but the text literal \\n which in C++ code you would write as string2 += "\\\\n";

Thanks Max - That is brilliant - “\\n” worked … ( two slashes not four )

( I meant to check out FireFox’s console over the weekend - but forgot about it this morning )

Thanks for taking your time to assist me … ( Hopefully others will benefit as well )

I now realise that PlatformIO has nothing to do with how the browser handles the code that is sent to form it’s webpage - the functionanlity of TextArea is provided entirely by the brower.

  • No wonder Max couldn’t understand what I was trying to explain.
1 Like