Currently running into an issue with this.
const configDataNode = document.getElementById('config_data');
const editor = CodeMirror.fromTextArea(
document.getElementById('config_data_editor'),
{
// lineNumbers: true,
mode: 'javascript',
// tabSize: 2,
// indentWithTabs: true,
// value: JSON.stringify(gon.config.initialData, 2, 2),
},
);
editor.on('change', changeObject => {
const {text} = changeObject;
configDataNode.value = text;
});
Here is my code.
Currently running into an issue with this.
const configDataNode = document.getElementById('config_data');
const editor = CodeMirror.fromTextArea(
document.getElementById('config_data_editor'),
{
// lineNumbers: true,
mode: 'javascript',
// tabSize: 2,
// indentWithTabs: true,
// value: JSON.stringify(gon.config.initialData, 2, 2),
},
);
editor.on('change', changeObject => {
const {text} = changeObject;
configDataNode.value = text;
});
Here is my code.
Share Improve this question edited Dec 25, 2020 at 14:14 Abdelsalam Shahlol 1,7791 gold badge24 silver badges33 bronze badges asked Dec 30, 2018 at 22:26 Overload119Overload119 5,4265 gold badges32 silver badges37 bronze badges2 Answers
Reset to default 7It is happening due to TextArea
object's value field is undefined
and thus inside the CodeMirror
codemirror.js
library options.value
is initialising the doc
variable also undefined, and thus later in source modeOption
is getting matched with doc child field (if the doc is undefined, how a object key may exists).
var textarea_editor = document.getElementById("RichTextArea");
// so explicitly assign value to textarea object.
textarea_editor.value = "";
this.editor = CodeMirror.fromTextArea(textarea_editor, {
tabSize: 4,
mode: 'text/plain',
theme: 'default',
lineNumbers: true,
styleActiveSelected: true,
styleActiveLine: true,
indentWithTabs: true,
matchBrackets: true,
highlightMatches: true,
});
Hope this may help someone.
The issue was that document.getElementById('config_data_editor')
is not a textarea.