[英]Symfony 4 form with ckeditor textarea not submitted
我需要在我的网站上使用所见即所得的编辑器。 我使用symfony 4。
我尝试使用ckeditor 5 CDN( https://ckeditor.com/ckeditor-5/download/ )
该视图运行良好,但未提交symfony表单。 (由于使用ckeditor,textareatype可能会杀死表格,因为它已被更改为许多div,并且textarea部分可能被视为空白)
这是形式为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 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”。
编辑:这个答案是为ckeditor 4而不是5
ckeditor无法实时更新字段。 您需要在提交表单之前调用updateElement ckeditor函数。
请参阅: https : //ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#method-updateElement
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.