Text format in textarea

984 views
Skip to first unread message

ilyal levin

unread,
Feb 15, 2012, 12:00:42 PM2/15/12
to General Dart Discussion
Hi

Suppose i have a textarea and i'm trying to
set some marked text to bold. how do i do that in dart?

I'm trying to take the marked text and attach the <b> tag
instead of setting the style attribute by .style.cssText = "x";

Thanks.

Seth Ladd

unread,
Feb 15, 2012, 2:41:56 PM2/15/12
to ilyal levin, General Dart Discussion
A textarea isn't useful for rich text editing, as you have discovered. There are some open source projects like YUI's Rich Text Editor that should help.

I haven't tried it, but you should be able to use something like the above, and grab the content via Dart (straight from the DOM). I'm not aware of a Dart port of a Rich Text Editor.

Sam McCall

unread,
Feb 15, 2012, 3:46:01 PM2/15/12
to Seth Ladd, ilyal levin, General Dart Discussion
Another option is contenteEditable, which is an attribute you can set
on a DOM node to make the contents editable. You do need a bit of
scripting to get formatting, but this is standard DOM stuff and should
be available in dart:html (or failing that dart:dom).

There's a quick intro here:
http://www.quackit.com/html/codes/contenteditable.cfm
and reference info on MDN:
https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla
Browser support information and a couple of other interesting links here:
http://caniuse.com/#search=contenteditable

ilyal levin

unread,
Feb 16, 2012, 4:06:55 AM2/16/12
to General Dart Discussion
Thanks for the help.

The YUI's Rich Text Editor is too complicated for my purpose.
The contenteEditable option is what 'm looking for
but it doesn't work in a textarea case.
if i do:
var txt = document.query('#textareaID');
var element = new Element.html('<b> +txt.value+'</b>');

I have 2 problem to overcome: select a specific txt in the texarea and
somehow to return it
to the textarea wrapped with the new tags.



On Feb 15, 10:46 pm, Sam McCall <sammcc...@google.com> wrote:
> Another option is contenteEditable, which is an attribute you can set
> on a DOM node to make the contents editable. You do need a bit of
> scripting to get formatting, but this is standard DOM stuff and should
> be available in dart:html (or failing that dart:dom).
>
> There's a quick intro here:http://www.quackit.com/html/codes/contenteditable.cfm
> and reference info on MDN:https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla
> Browser support information and a couple of other interesting links here:http://caniuse.com/#search=contenteditable
>
>
>
>
>
>
>
> On Wed, Feb 15, 2012 at 8:41 PM, Seth Ladd <sethl...@google.com> wrote:
> > A textarea isn't useful for rich text editing, as you have discovered. There
> > are some open source projects like YUI's Rich Text Editor that should help.
>
> > I haven't tried it, but you should be able to use something like the above,
> > and grab the content via Dart (straight from the DOM). I'm not aware of a
> > Dart port of a Rich Text Editor.
>

Sam McCall

unread,
Feb 16, 2012, 5:35:49 AM2/16/12
to ilyal levin, General Dart Discussion
Textareas don't support formatted text, so there's no way to make this work.
If you need formatted text, you have to use a <div> or some other element.

To make it editable your options are:
* contentEditable
* an existing JS rich-text-editor (like YUI's)
* write your own RTE in dart (lots of low-level DOM work).

But to reiterate, none of this will ever work in a <textarea>.

Reply all
Reply to author
Forward
0 new messages