hvlads / django-ckeditor-5

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

Feature Request: Make django-ckeditor-5 compatible with django-nested-admin #137

Closed nattyg93 closed 1 year ago

nattyg93 commented 1 year ago

Hi folks,

I'm trying to use this package with django-nested-admin. Due to the way nested admin's js handles replacing __prefix__ when adding inlines (relevant source), it misses django-ckeditor5's ids.

This is by no means a bug in django-ckeditor5, but I'm hoping we could update django-ckeditor5 to make it compatible.

There are two issues that would need to be addressed.

Firstly, nested admin will only replace __prefix__ when the attrs' values start with id_.... source for the full regex. So the work around to make it compatible is to simply change the prefixes used in django-ckeditor5 to suffixes, e.g. <input type="hidden" id="ck-editor-5-upload-url-{{script_id}}".... would become <input type="hidden" id="{{script_id}}-ck-editor-5-upload-url".... etc.

Secondly, nested admin has an allowlist of element selectors it uses to decide whether to update the attrs' values. div and script are not in that allowlist, so those ids are skipped even after updating the prefix to be a suffix. The workaround here is to replace:

Finally, app.js would need to be updated to look for the new ids.

I'm happy to create a PR for this if you're open to it.

Cheers, Nat

PS. Love this package and thanks for all the hard work!

nattyg93 commented 1 year ago

I've gone ahead and applied the changes to a fork https://github.com/nattyg93/django-ckeditor-5/tree/feature/django-nested-admin-support

Please let me know if you would accept this as a PR?

nattyg93 commented 1 year ago

I've also identified another issue with the initialisation script which I've also fixed.

hvlads commented 1 year ago

Hi, thanks for the issue, I couldn't test it, I don't think we need to change the compatibility code with each django add-on, but I'll think in the future how to make this code universal