Skip to content
Advertisement

codemirror.setOption(‘mode’,val) isnt working

I am trying to make a text editor with firepad and codemirror, everything works perfectly on page loading, but when I try to change the mode on button click, the function gets called but

JavaScript

doesn’t seem to work. I am calling the following code on the onload event of the body (works perfectly):

JavaScript

on button click event I am calling the following code (problem here!):

JavaScript

This is just a miniaturized sample of the code (the relevant one).

I am using as a resources for the mode reloading and for firebase with codemirror the following:

https://firepad.io/docs/

https://codemirror.net/demo/loadmode.html#

Scripts and stylesheets being called are the following (the relevant ones only):

JavaScript

I am using Firefox and there is no errors on the developper console(it is just neither changing nor reloading). So what am I missing ?? Thanks in advance.

Advertisement

Answer

codemirror doesn’t accept “xml” as a mode type. What you’re looking for is “application/xml” or “text/xml”.

according to the documentation on CodeMirrors site, you need to call codemirror.findModeByExtension on your filename string’s extension to get an info object. You call CM_OBJ.setOption(“mode”,info.mime) first, then CodeMirror.autoLoadMode(editor,info.mode) if you want to use simpler and less specific typing strings.

this works for me on firefox and chrome from the inspect page. source: https://codemirror.net/demo/loadmode.html

Advertisement