未提交带有 ckeditor textarea 的 Symfony 4 表单

Symfony 4 form with ckeditor textarea not submitted

我需要在我的网站上使用所见即所得的编辑器。 我使用 symfony 4.

我试过使用 ckeditor 5 CDN (https://ckeditor.com/ckeditor-5/download/)

视图运行良好,但未提交 symfony 表单。 (textareatype 可能会杀死表单,因为使用 ckeditor 它会变成许多 div,textarea 部分可能会被视为空白)

这是表单中文本区域的代码。

->add('content', TextareaType::class, [
            'label' => "Content label",
            'required' => true,
            'attr' => [
                'class' => "ckeditor"
             ]
        ])

和脚本代码

<script>
    ClassicEditor
        .create( document.querySelector( '.ckeditor' ) )
        .catch( error => {
            console.error( error );
        } );
</script>

谢谢。使用一个简单的所见即所得编辑器是多么的困难,这是绝望的..

编辑:此答案适用于 ckeditor 4,不适用于 5

ckeditor 没有实时更新字段。您需要在提交表单之前调用 updateElement ckeditor 函数。

参见:https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#method-updateElement

我找到了解决方案。 我强调我使用的是 CKEditor 5.

ClassicEditor
        .create( document.querySelector( '.ckeditor' ) )
        .then( editor => {
            theEditor = editor;
        } )
        .catch( error => {
            console.error( error );
        } );

    document.getElementById("news_submit").addEventListener("click", function() {
        theEditor.updateSourceElement();
    });

该方法现在 "updateSourceElement" 使用 CKEditor 5。