Search code examples
flaskckeditorpython-3.8

Flask-CKEditor - Error code: editor-element-conflict


In my flask app, I have 2 instances of CKEditor on 2 different files.

        <div>
            {{ ckeditor.create(name="message_body") }}
            {{ ckeditor.load(pkg_type="standard") }}
            {{ ckeditor.config(name="message_body", width=1000, height=500) }}
        </div>

and

        <div>
            {{ ckeditor.create(name="newsletter_body") }}
            {{ ckeditor.load(pkg_type="standard") }}
            {{ ckeditor.config(name="newsletter_body", width=1000, height=500) }}
        </div>

Each of those <div> are in a {% block main %} I'm getting the data from from 2 different file with these lines:

request.form.get("message_body")

and

request.form.get("newsletter_body")

All seems fine, I get the data but in my browser I get this errors:

[CKEDITOR] Error code: editor-element-conflict. 
Object { editorName: "message_body" }

The related docs read this:

Description: There is already an editor’s instance attached to the provided element and attaching another one to it is not allowed.
Additional data:

    editorName: The name of the already attached editor.

But I don't understand why. Can any one help me get rid of these errors? Many thanks


Solution

  • I just release 0.4.5 to fix this, please upgrade:

    pip install -U flask-ckeditor
    

    The reason behind this error is:

    When you add a "ckeditor" class to a textarea element, CKEditor will try to initialize a CKEditor editor box on top of it. At the same time, if you initialize a CKEditor editor box manually with CKEDITOR.replace(...) (which is what the ckeditor.config() does), the error happens: you can't initialize two CKEditor editor box on one textarea element.