hvlads / django-ckeditor-5

Django CKEditor 5 integration.
Other
152 stars 60 forks source link

Update app.js to enable usage with django-content-editor #255

Closed frague59 closed 1 month ago

frague59 commented 1 month ago

Add a try/catch block in the resolveElementArray function to avoid issues on CKEditor initialization. See https://github.com/feincms/django-content-editor/issues/30#issuecomment-2379439783

Fixes https://github.com/hvlads/django-ckeditor-5/issues/253

frague59 commented 1 month ago

I'm not sure which branch of the ternary operator I should use.

goapunk commented 1 month ago

@frague59 thanks :) according to the linked issue the problem comes from passing the wrong parameter in the callback for the formset event, wouldn't it be enough to change line 156 django.jQuery(document).on("formset:added", createEditors); to django.jQuery(document).on("formset:added", () => createEditors()); then ? :) Could you test if that's already enough to make it work ?

frague59 commented 1 month ago

Thanks for your quick answer.

I've tried the proposed patch about django.jQuery(document).on("formset:added", () => createEditors());, but I've still an issue about the element.matches(query) not defined in the browser, at the CKEditor creation. Editor is created, but the other handlers bound to the formset:added event are failing.

goapunk commented 1 month ago

Thanks for your quick answer.

I've tried the proposed patch about django.jQuery(document).on("formset:added", () => createEditors());, but I've still an issue about the element.matches(query) not defined in the browser, at the CKEditor creation. Editor is created, but the other handlers bound to the formset:added event are failing.

@frague59 thanks for testing. Interesting that it doesn't fix it. Could you test a again and simply remove that line completely? I'm not actually sure that's the cause of the issue, it might be the MutationObserver. Is your project public so we can test ourselves?

frague59 commented 1 month ago

I've tested with django.jQuery(document).on("formset:added", () => createEditors());, it works for my usage. I'll propose another PR.