Monaco-editor: Ability to grab contents of editor as text.

Created on 23 Jun 2016  路  3Comments  路  Source: microsoft/monaco-editor

Is this a possibility? Say I wanted to include the contents of the editor as part of a form and submit the entered text? Codemirror supports this by allowing you to bind the editor to a textarea. Binding it like this is not really necessary in my specific situation but an easy call to grab the contents of the editor as text would be helpful. Is this possible?

Most helpful comment

Yes, Try this in the playground

var editor = monaco.editor.create(document.getElementById("container"), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: "javascript"
});
console.log(editor.getValue())

All 3 comments

Yes, Try this in the playground

var editor = monaco.editor.create(document.getElementById("container"), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: "javascript"
});
console.log(editor.getValue())

Awesome thanks for the quick response. I had assumed there was a simple solution to this but was for some reason unable to find it.

So, it's not OK to put the editor inside a <form> and expect to get the full content to be send to the server. The value should be retrieved with editor.getValue() just before submit the form.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chengtie picture chengtie  路  3Comments

spotqa-josem picture spotqa-josem  路  3Comments

Panhaiwei picture Panhaiwei  路  3Comments

Spongman picture Spongman  路  3Comments

inf9144 picture inf9144  路  3Comments