django-cms / djangocms-text-ckeditor

Text Plugin for django CMS using CKEditor 4
https://www.django-cms.org/en/repositories-plugins/
BSD 3-Clause "New" or "Revised" License
167 stars 185 forks source link

HTMLField in Django InlineAdmin causes TypeError when adding new record #657

Closed lab360-ch closed 4 months ago

lab360-ch commented 11 months ago

I have a Model with an HTMLField in it. The Model with the HTMLField is used as StackedInline in the Django Admin.

When I add a new record, the CKEditor is not shown, instead only the Textarea is displayed, and I got a JavaScript Error: TypeError: Cannot read properties of undefined (reading 'replace').

image

The model Looks like this:

class CategoryTextSlide(models.Model):
    category = models.ForeignKey(
        Category,
        related_name="slides",
        verbose_name="Kategorie",
        on_delete=models.CASCADE,
    )

    text = HTMLField(
        verbose_name="Text",
        configuration="CKEDITOR_CATEGORY_TEASER_SLIDE_SETTINGS",
    )

    class Meta:
        verbose_name = "Kategorie Text Slide"
        verbose_name_plural = "Kategorien Text Slides"

The CKEditor settings like this:

CKEDITOR_CATEGORY_TEASER_SLIDE_SETTINGS = {
    "bodyClass": "category-teaser-slide",
    "toolbar_HTMLField": [
        ["Undo", "Redo"],
        ["Format", "RemoveFormat", "Bold", "Link"],
        ["Source", "Maximize"],
    ],
    "contentsCss": "/static/ckeditor.css",
    "format_tags": "h3;p",
}

And the Admin config like this:

class CategoryTextSlideAdmin(admin.StackedInline):
    model = CategoryTextSlide
    min_num = 1
    extra = 0

I use the following version:

Thanks for helping.

Best regards

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

marksweb commented 8 months ago

This looks like you'd need to add custom javascript to instantiate a new ckeditor when you add a new inline.

This maybe considered outside of the scope of the plugin though as I'm not clear on how you're using it. This seems like regular Django.

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 months ago

This will now be closed due to inactivity, but feel free to reopen it.