【问题标题】:Symfony 4 form with ckeditor textarea not submitted未提交带有ckeditor textarea的Symfony 4表单
【发布时间】:2018-11-03 20:09:44
【问题描述】:

我需要在我的网站上使用所见即所得的编辑器。 我使用 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>

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

【问题讨论】:

    标签: javascript symfony ckeditor symfony4 ckeditor5


    【解决方案1】:

    我找到了解决方案。 我强调我使用的是 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();
        });
    

    该方法现在是 CKEditor 5 的“updateSourceElement”。

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 问题是关于 CKEditor 5,而不是 CKEditor 4。
      猜你喜欢
      • 1970-01-01
      • 2011-03-16
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多