Dominus77 / yii2-tinymce-widget

TinyMCE 4 widget for Yii2.
MIT License
8 stars 0 forks source link

The editor does not work after a double call renderAjax () #8

Closed w4ugit closed 3 years ago

w4ugit commented 3 years ago

I upload content using renderAjax (). When I do it for the first time - everything works well, the editor is displayed. But when I try to download content again via renderAjax () (without reloading the page) - the editors are not displayed

Dominus77 commented 3 years ago

Most likely you need to re-initialize the editor.

w4ugit commented 3 years ago

Most likely you need to re-initialize the editor.

how to do it if i call it just as a widget? <?= TinyMce::widget([ 'options' => [ 'rows' => $model->options['rows'], 'placeholder' => true, 'data-role' => 'widgetEditor' ], 'model' => $model->model, 'attribute' => $model->attribute, 'language' => 'ru', 'clientOptions' => [ 'menubar' => false, 'statusbar' => true, 'theme' => 'modern', 'skin' => 'lightgray-gradient', //charcoal, tundora, lightgray-gradient, lightgray 'plugins' => [ "advlist autolink lists link image charmap print preview hr anchor pagebreak placeholder", "searchreplace wordcount visualblocks visualchars code fullscreen", "insertdatetime media nonbreaking save table contextmenu directionality", "emoticons template paste textcolor colorpicker textpattern imagetools codesample toc noneditable", ], 'noneditable_noneditable_class' => 'fa', 'extended_valid_elements' => 'span[class|style]', 'toolbar1' => "bold italic underline| bullist numlist", 'image_advtab' => true, 'content_css' => [ '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i', '//www.tinymce.com/css/codepen.min.css', ] ], 'fileManager' => [ 'class' => MihaildevElFinder::className(), ] ]); ?>

Dominus77 commented 3 years ago

Before loading the editor, you must delete the existing one.

View:

$script = "
    let url = '$url';    
    // Load editor via ajax
    $('#load').on('click', function(){
        $.ajax({
            url: url,            
            type: 'post',
        }).done(function (response) {           
            $('#editor').html(response);            
        }).fail(function (response) {
            console.log(response);
        });
    });

    // Remove
    $('#remove').on('click', function(){
        tinymce.remove();
        $('#editor').text('');
    });
";
$this->registerJs($script);
<button id="load">Load Editor</button>
<button id="remove">Remove Editor</button>
<div id="editor"></div>