PDA

View Full Version : How catch (and replace) carriage returns in a Ext.form.TextArea value



dreamin
14 Sep 2010, 6:40 AM
Hi all,
I have a normal Ext.form.TextArea who saves its data into a normal mysql database.
When I load the text into the TextArea all is fine: the carriage returns are hidden, but they exists because the text is splitted into lines.
My problem is to show that text into a web page, but mantaining the text format, so the carriage returns must be ideally replaced by a <br/>.

[start of the example]

TEXT IN MY TEXTAREA:
---------------------------
Hallo,
this is my foo text.

Do you like it?

SAME TEXT, SHOWN IN A WEBPAGE
----------------------------------------
Hallo, this is my foo text. Do you like it?

[end of the example]

Someone can suggest me the right way to operate? Thanks!

Condor
14 Sep 2010, 6:46 AM
When exactly do you want to replace carriage returns with <br/>s?

ps. You can use the Ext.util.Format.nl2br function to do this.

dreamin
14 Sep 2010, 6:59 AM
Hi Condor,
thanks in advance for your fast suggestion!

I want to replace it at a PHP level, so maybe I must do this:

1. add a new field to the db table, named "html_description" (current one is named simply "description")
2. add a "onblur" listener to the textarea which fills a hidden input of the form, named "html_description"
3. save the normal text in the "description" field of the db table, and the html text in the "html_description" (using your suggestion), so the first text will be used always in the textarea and the 2nd in the web pages

darthwes
14 Sep 2010, 7:17 AM
function ta_renderer(v) {
return Ext.util.Format.nl2br(v);
}
...
{
dataIndex: whatevID,
type: 'string',
editor: new Ext.form.TextArea({
allowBlank: false,
...
}),
renderer: ta_renderer,
...
}
...


Just set up a renderer?

dreamin
15 Sep 2010, 2:12 PM
Thank you darthwes.
I chose to add a "keypress" listener to the textarea, who fills a hidden field of the form with the text formatted by Ext.util.Format.nl2br function.

Many thanks,
Michele