Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

instance of CKeditor already exists

I have found a few similar posts on this on Stack overflow but there are none with an answer that is working.

I have a few tabs on a page, depending on that li they click on they will see a specific tab. In one of the tabs there is a CKeditor which is initiated on the click of the li. When they user clicks off that specific tab onto another one, and then returns there is this error:

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

Here is the JS:

    $('.addVacancy').click( function() {
        if(CKEDITOR.instances.employDesc)  {
            alert('instance exists');
            var editor = CKEDITOR.instances[employDesc];
            if (editor) { 
                editor.destroy(true); 
            } 
            alert('distroyed');
        }   
        CKEDITOR.replace('employDesc');
    });

Both of the alerts appear but then it breaks as the error comes on in the console. Can anyone help with this?

Thanks

like image 675
MarkP Avatar asked Apr 09 '14 08:04

MarkP


People also ask

How do I get the instance of Ckeditor?

oEditor = CKEDITOR. currentInstance; this will give you the current instance.

How do I know if Ckeditor is loaded?

// At the top of the script CKEDitor_loaded = false; // then later CKEDITOR. on('loaded', function(){ CKEditor_loaded = true; }); Instead of a global variable, you could also consider setting something inside CKEDITOR : CKEDITOR.

How do you hide and show Ckeditor?

visibility = 'hidden';"+ ""+ "}" + "}" + "}"; This still works in hiding the DIV and in version 2.6 it would also appear to be hidden but in 3.0 the editor is still very much visible.

What is Ckeditor replace?

The CKEditor 4 Find and Replace feature allows for finding and replacing any text in the editor easily. It helps the user find words, word parts or phrases matching the case of the searched text, which is especially helpful in lengthy documents and one that may utilize certain words in different contexts.


1 Answers

if (CKEDITOR.instances['tresc']) {
    CKEDITOR.remove(CKEDITOR.instances['tresc']);
} else{
    CKEDITOR.replace( 'tresc');
}
like image 149
macieks Avatar answered Oct 09 '22 09:10

macieks