Tuesday 10 September 2019

Cannot get instance of CKEditor

I have several fields which need to be initialized with CKEditor, for this I have created an helper class that contains the initEditor method.

The method below should return the initialized editor but it doesn't:

window.CKEditorHelper = window.CKEditorHelper || {};

(function (exports) {

    exports.initEditor = function (input, myEditor) {
        ClassicEditor
            .create(document.querySelector(input), {
                language: {
                    ui: 'en'
                    content: 'en'
                }
            })
            .then(editor => {
                myEditor = editor;
            });
    };

})(window.CKEditorHelper);

this is called in the following way:

let editor = null;
CKEditorHelper.initEditor('#description', editor);

so when I click on a button:

$('#save').on('click', function(){
    console.log(editor.getData());
});

I get:

Cannot read property 'getData' of null

what I did wrong?



from Cannot get instance of CKEditor

No comments:

Post a Comment