Setting the text of the label programmatically ignores the newline characters in ExtJS

402 Views Asked by At

I have this web app where it periodically fetches data from a database and then displays it the retrieved data in a Label.

This is what I do after the store gets loaded and then the record count is greater than 0 (meaning that I have data):

Ext.getCmp('labelIDHere').
          setText(messageStore.first().get("value"), true/false);

I've tried to use html encoding and not use it, however, it does not work at all. For example, if the database input is:

Foo Bar!
Lorem Ipsum Dolor.

What I end up getting is:

Foo Bar!  Lorem Ipsum Dolor.

And the really weird thing about this is that both the database record (MySQL) and the console.log show:

Foo Bar!
Lorem Ipsum Dolor.

I logged it before and after I displayed it just to check if ExtJS was manipulating the entry as it fetched the records, but to no avail, the data was fetched as intended, but somehow could not be displayed as wanted.

I've tried using <br /> and %0D%0A but neither of those worked.

1

There are 1 best solutions below

0
On

(I swear to God, if we all had a dollar every time we found the answer within minutes of posting a question, some of us would be quite rich)

Here:

var value = messageStore.first().get("value").replace("\n","<br/>"); 
Ext.getCmp('labelIDHere').setText(value, false);

Basically what happens is that since you can't set a newline character in a label, what I did was that I replaced all newline characters with a breakpoint instead.

If you're having trouble storing newline, you can try the variants such as %0D%0A