CKEditor instance already exists

前端 未结 30 3551
刺人心
刺人心 2020-11-27 11:24

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

Whe

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 12:14

    I had exactly the same problem like jackboberg. I was using dynamic form loading into jquery dialogs then attaching various widgets (datepickers, ckeditors etc...). And I tried all solutions noted above, none of them worked for me.

    For some reason ckeditor only attached the first time I loaded form, the second time I got exactly the same error message jackboberg did.

    I've analyzed my code and discovered that if you attach ckeditor in "mid-air" that is while form content is still not placed into dialog, ckeditor won't properly attach its bindings. That is since ckeditor is attached in "mid-air", second time you attach it in "mid-air"... poof ... an error is thrown since the first instance was not properly removed from DOM.

    This was my code that ptoduced the error:

    var $content = $(r.content); // jQuery can create DOM nodes from html text gotten from  - so called "mid-air" DOM creation
    $('.rte-field',$content).ckeditor(function(){});
    $content.dialog();
    

    This is the fix that worked:

    var $content = $(r.content).dialog(); // first create dialog
    $('.rte-field',$content).ckeditor(function(){}); // then attach ckeditor widget
    

提交回复
热议问题