I can create and display multiple dynamic codemirror instances, but I CANT reference them with the below code. Think the issue is that I need to create a dynamic function name. (Not 100% on how to do so here)
var function (somefilename, xml){
var instanceName = somefilename + 'Editor';
require([
'codemirror/lib/codemirror','codemirror/mode/xml/xml',
'codemirror/addon/search/search'
], function(CodeMirror) {
instanceName = CodeMirror.fromTextArea(document.getElementById(somefilename + 'xml'), {
lineNumbers: true,
mode: 'xml'
});
instanceName.setValue(xml);
instanceName.focus();
});
};
I actually was going about this the wrong way and should have been utilizing an object to store said multiple instances. Which of course gives me the ability to reference ANY stored records.
Hope this helps someone in the future!
//Create your object to store multiple instances of CodeMirror
var cmInstances = {}
function createInstance(someId) {
In my case I will be using requirejs to load 'on demand'
require([
'codemirror/lib/codemirror', 'codemirror/mode/xml/xml',
'codemirror/addon/search/search'
], function(CodeMirror) {
So what I'm doing below is creating a instance of the Codemirror object within my object. That essentially keys to the ID I've previously passed in the function (ie: 'someId). Also before I called the below I've had a previous function create a 'textarea' that I've injected into the page named '#someID_xml'. Hence the reference for getElementByID
cmInstances[someId] = CodeMirror.fromTextArea(document.getElementById(someId + '_xml'), {
lineNumbers: true,
mode: 'xml'
});
});
};