Search code examples
javascriptcodemirror

Codemirror fromTextArea error: options.value is undefined


I actually have a completely different error related to hidden tabs but when I have come to create a simplified fiddle example I am getting this error:

Error: TypeError: options.value is undefined
Source File: http://codemirror.net/lib/codemirror.js
Line: 55

Example: http://jsfiddle.net/gWZeQ/

var editor = CodeMirror.fromTextArea(document.getElementById("test1"));  

<texarea id="test1" name="test1">function test() { 
    return false;
}</texarea>

Solution

  • I'm not sure why your code doesn't work, according to the docs it's fine.

    However, here's a code that works ok :)

    var myTextArea = document.getElementById("test1"),
    var editor = CodeMirror(function(elt) {
      myTextArea.parentNode.replaceChild(elt, myTextArea);
    }, {value: myTextArea.innerHTML});
    

    Demo: http://jsfiddle.net/edgarinvillegas/gWZeQ/1/

    Cheers, from La Paz, Bolivia