View Full Version : TextArea or HtmlEditor styling on render only?

24 Sep 2012, 7:42 AM
I have some interesting case here.
TextArea or HtmlEditor (lets call itTextBox) values are loaded and saved to db in plaintext format.
I DONT want to save html in db. Or at least don't want to allow full HTML.
So i would prefer to use TextArea but Dont mind to have minimalistic HtmlEditor also. Like "List" or "Bold/Italic" styles are useful but don't want more of it.

Why do I need this?

I have long article. I want to highlight article keywords within text as help the person who's editing it, but these highlighting styles should not be published.

My question here is: how can I highlight some text in the TextBox at rendertime without saving this hightlight styles to db.

Lets say I have this text: "Some very long plain text that I want to save to DB".

I want to set color of "very long" to be blue. But I don't want to save <font color="blue"> to db.
So when I do field.getValue() I would get "Some very long plain text that I want to save to DB" but in the TextBox it should be "Some <blue>very long</blue> plain text that I want to save to DB".

Sure I could do html cleanup on server side, or assign custom style which will be overriden by website stylesheets. But this rather a hacking around rather providing clean solution.

So I would prefer something similar to ComboBox where there are 2 values: getValue() and getRawValue().

Would be happy to get some suggestions. Thanks!

24 Sep 2012, 10:37 AM
If the formatting is not saved, how do you expect it to remember on reload?
You could perhaps have a companion field for this, but you would have to do the work yourself.


25 Sep 2012, 1:12 AM
restorring formatting is easy: Everytime field is loaded it passes through a "renderer" function which does the formatting. It knows keywords and styles. All has to do is replace "matching text" with <b>matching text</b>.

it's very easy done in grid with renderer: function().. but unfortunately inputfields don't have such method.

what do you mean by companion field?


3 May 2018, 12:37 AM
I believe you could override the setValue function of the field to call the setRawValue:

setValue: function(value) {
this.superclass.setValue.apply(this, arguments);
this.setRawValue(some_formatted_value); //call setRawValue here