Search code examples
javascriptcodemirror

How do I resolve an AutoComplete error when using CodeMirror?


I want to use the AutoComplete of CodeMirror, but I'm getting the error:

Uncaught TypeError: Cannot read property 'javascript' of undefined

CodeMirror.commands.autocomplete = function(cm) {
    CodeMirror.showHint(cm, CodeMirror.hint.javascript); // Error Here
}

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    extraKeys: {"Ctrl-Space": "autocomplete"}
});

Solution

  • In order to use autocomplete capabilities, you must insure to include the appropriate scripts, i.e. show-hint.js, show-hint.css and javascript-hint.js (which seems like the one causing the fuss here).

    Take a look at the autocomplete demo's source code for a reference.