esiaz
esiaz

Reputation: 619

CKeditor doesn't work with content rendered with renderAjax()

I installed CKeditor for Yii2 according to extension docs.

I have pages in rendered in controller for eg.:

public function actionTest($id)
{
    $model = $this->findModel($id);

    return $this->renderAjax('/test', ['model' => $model]);
}

CKeditor loads properly if it is via:

return $this->render('/test', ['model' => $model]); 

but does not load if it is loaded via renderAjax(). Seems to be CKeditor's jquery missing in this content. May I know how to add it to this page?

In my view:

    <?= $form->field($model, 'Desc')->label('Description'. Html::tag('span', '*',['class'=>'required']))->widget(CKEditor::className(), [
            'options' => ['rows' => 6],
            'preset' => 'basic'
        ]) 
    ?>   

Upvotes: 0

Views: 589

Answers (1)

arogachev
arogachev

Reputation: 33538

In case of dynamically loaded textarea you need to reinitialize CKEditor in AJAX success callback.

It can be done like so:

CKEDITOR.replace('id-of-your-textarea-field');

Links:

Upvotes: 1

Related Questions