未提交带有ckeditor文本区域的Symfony 4表格



我需要在我的网站上使用wysiwyg编辑器。我使用symfony 4。

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

视图运行良好,但符号形式未提交。(文本区域类型可能会破坏表单,因为使用了ckeditor,它被更改为许多div,并且文本区域部分可能被视为空白(

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

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

和脚本的代码

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

谢谢。使用一个简单的wysiwyg编辑器是多么困难,真是令人绝望。。

我找到了解决方案。我强调我使用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"。

编辑:这个答案适用于cketator 4,而不是5

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

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

最新更新