[ace] How to use Ace in a form?

2,061 views
Skip to first unread message

Steven Campbell

unread,
Feb 4, 2011, 9:56:36 AM2/4/11
to Ajax.org Cloud9 Editor (Ace)
I want to use Ace in an HTML textarea element, but there doesn't seem
to be any documentation on this. It seems only to work with non-form
elements like div and pre.

Alternatively, is there any Javascript code I could use to pull the
contents of Ace into a variable? I was originally doing it with
textarea's "value" attribute, but if Ace can't work with textareas, is
there another way to pull the content?

Kevin Dangoor

unread,
Feb 4, 2011, 10:02:34 AM2/4/11
to ace-d...@googlegroups.com
On Fri, Feb 4, 2011 at 9:56 AM, Steven Campbell <d.steven...@gmail.com> wrote:
I want to use Ace in an HTML textarea element, but there doesn't seem
to be any documentation on this. It seems only to work with non-form
elements like div and pre.


Bespin has code that will transparently upgrade a textarea (it keeps the textarea around but hides it and stuffs the contents of Bespin into the textarea for form posting and such).

This code has not been ported forward to Ace (patches accepted :)
 
Alternatively, is there any Javascript code I could use to pull the
contents of Ace into a variable? I was originally doing it with
textarea's "value" attribute, but if Ace can't work with textareas, is
there another way to pull the content?


Yes, this you can definitely do...

document.getElementById("editor").env.document.getValue()

will do it for a div or whatever with the ID of editor, I believe.



--
Kevin Dangoor

work: http://mozilla.com/
email: kdan...@mozilla.com
blog: http://www.BlueSkyOnMars.com

Giles Thomas

unread,
Feb 4, 2011, 10:13:35 AM2/4/11
to ace-d...@googlegroups.com
Steven Campbell wrote:
> Alternatively, is there any Javascript code I could use to pull the
> contents of Ace into a variable? I was originally doing it with
> textarea's "value" attribute, but if Ace can't work with textareas, is
> there another way to pull the content
Try this:

// Setup
editor = ace.edit("my_div");

// Read
text = editor.getSession().getValue()


Cheers,

Giles

--
Giles Thomas
giles....@resolversystems.com
+44 (0) 20 3051 2751

Dirigible: a programmable cloud spreadsheet
<http://projectdirigible.com/>

17a Clerkenwell Road, London EC1M 5RD, UK
VAT No.: GB 893 5643 79
Registered in England and Wales as company number 5467329.
Registered address: 843 Finchley Road, London NW11 8NA, UK


Ramon

unread,
Mar 11, 2011, 4:49:23 AM3/11/11
to ace-d...@googlegroups.com
Cool. I'm excited for this! It'd be a lot nicer to have a drag and drop replacement of textareas. Having to add extra js code to manage each textarea replacement is, well, dirty :)
Reply all
Reply to author
Forward
0 new messages