aliensurfer
aliensurfer

Reputation: 1650

ExtJs textarea multiline issue

How can I assign text containing \r\n to an ExtJs textarea and get to see line breaks instead of the actual \r\n characters? When I manually press the Enter key and check Firebug, I can see \r\n getting inserted. But if I assign a string containing \r\n to the textarea, it renders as-is.

Any hints would be helpful.

Upvotes: 6

Views: 8444

Answers (3)

Ramesh Roddam
Ramesh Roddam

Reputation: 283

Try this:

Replace all occurrences of \r\n with \n globally. g - represents replace all occurrences of \r\n with \n and it will move to the next line.

var formattedText=text.replace(/\\n/g,'\r\n');
Ext.ComponentQuery.query('#id')[0].setValue(formattedText);

Upvotes: 0

aliensurfer
aliensurfer

Reputation: 1650

I solved it myself. I was using the 'html' property to assign the \r\n-riddled text to the textarea. I changed that to 'value', and it works like a charm. Thanks anyway.

Upvotes: 5

Lloyd
Lloyd

Reputation: 29668

Try:

var text = text.replace('\r\n',"" + String.fromCharCode(13) + String.fromCharCode(10));

Upvotes: 0

Related Questions