0

I've written this code using mithril.js + CKEditor

<body>
    <script>
        var frm = {};

        frm.vm = (function () {
            var vm = {};

            vm.afterLoad = function () {
                CKEDITOR.replace( 'editor1' );
            };

            vm.btnClick = function () {
                console.log(document.getElementById('editor1').value);
            };

            return vm;
        })();

        frm.controller = function () {

        };

        frm.view = function (controller) {
            return m("div", {config: frm.vm.afterLoad}, [
                m("textarea", {id: "editor1"}),
                m("button", {onclick: frm.vm.btnClick}, "Click here to see the text you've typed")
            ]) 
            ;
        };

        m.mount(document.body, frm);
    </script>
</body>

but when I click the button, I see this error:

Uncaught The editor instance "editor1" is already attached to the provided element.

and console.log() prints a blank line.

What am I doing wrong?

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34

1 Answers1

0

I found the problem. To get the value of the CKEditor, one needs to use

CKEditor.instance.nameoftextarea.getData()
Pang
  • 9,564
  • 146
  • 81
  • 122