How to destroy a Ckeditor 5 instance

Viewed 4924

How can I unload a Ckeditor 5 instance from a form object? I can load it with ClassicEditor.create(). I found the editor.destroy() method but it does not work. The Javascript console says "editor.destroy is not a function".

Current testing code is:

<button type="button" onclick="ckEditor('load')">Start</button><button type="button" onclick="ckEditor('unload')">Stop</button>
<textarea id="welcomeText" class="form-control" tabindex="21" name="txt_welcomeText" rows="10"><p>This is my welcome text.</textarea>
<script>
   function ckEditor(action) {
      editor = ClassicEditor.create( document.querySelector( '#welcomeText' ) ).catch( error => {console.error( error );});
      if (action == "unload") editor.destroy();
   }
   </script>

Best regards,

George

2 Answers

There's a need to wait for the promise in order to get the CKEditor 5 editor's instance.

ClassicEditor.create( element )
   .then( editor => editor.destroy() )
   .catch( err => console.error( err ) ) 
Related