CKEditor instance already exists

前端 未结 30 3488
刺人心
刺人心 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 11:52

    I am in the situation where I have to controls that spawn dialogs, each of them need to have a ckeditor embedded inside these dialogs. And it just so happens the text areas share the same id. (normally this is very bad practice, but I have 2 jqGrids, one of assigned items and another of unassigned items.) They share almost identical configuration. Thus, I am using common code to configure both.

    So, when I load a dialog, for adding rows, or for editing them, from either jqGrid; I must remove all instances of CKEDITOR in all textareas.

    $('textarea').each(function()
    {
        try 
        {
            if(CKEDITOR.instances[$(this)[0].id] != null)
            {
                CKEDITOR.instances[$(this)[0].id].destroy();
            }
        }
        catch(e)
        {
    
        }
    });
    

    This will loop over all textareas, and if there is a CKEDITOR instance, then destroy it.

    Alternatively if you use pure jQuery:

    $('textarea').each(function()
    {
        try 
        {
            $(this).ckeditorGet().destroy();
        }
        catch(e)
        {
    
        }
    });
    

提交回复
热议问题