2amigos / yii2-ckeditor-widget

CKEditor WYSIWYG widget for Yii2.
https://2amigos.us/open-source/ckeditor-widget
Other
172 stars 112 forks source link

uncaught exception: The editor instance "w0" is already attached to the provided element. #51

Closed msliman closed 8 years ago

msliman commented 8 years ago

I had this problem appeared in console.

tonydspaniard commented 8 years ago

mind sharing the code¿

buttflattery commented 5 years ago

@tonydspaniard , its when you use the CKEditorInline widget with the basic code given in the example on the github page,

<?php CKEditorInline::begin(['preset' => 'basic']);?>
    This text can be edited now :)
<?php CKEditorInline::end();?>

also, it loads the jquery from the adapter/jquery.js and adds a dependency on yii\web\JqueryAsset too which results in adding 2 jquery files.

AndreyBCC commented 5 years ago

For fixing it create your widget copy which extends from CKEditorInline and implement protected function registerPlugin() in which copy code of registerPlugin function but replace row $js[] = "CKEDITOR.inline('$id', $options);";

by this code: $js[] = <<<JS if (CKEDITOR.instances['$id']) { CKEDITOR.instances['$id'].destroy(true); } CKEDITOR.inline('$id', $options); JS;

CKEDITOR.instances['$id'].destroy will show notifications in console "Error code: editor-incorrect-destroy." because the editor is being destroyed before it is fully initialized. But widget will work correctly