1
votes

I need to use a wysiwyg editor on my website. I use symfony 4.

I've tried to use ckeditor 5 CDN (https://ckeditor.com/ckeditor-5/download/)

The view works well but the symfony form is not submitted. (the textareatype may kills the form because with ckeditor it is changed into many divs and the textarea section may be considered blank)

this is the code of the textarea which is in the form.

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

and the code of the script

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

Thanks. it's hopeless how it's difficult to use a simple wysiwyg editor ..

2

2 Answers

1
votes

I found the solution. I emphasize that i use 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();
    });

the method is now "updateSourceElement" with CKEditor 5.

0
votes

edit: this answer is for ckeditor 4 not for 5

ckeditor not update field in real time. You need to call updateElement ckeditor function before submit your form.

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