django-unfold icon indicating copy to clipboard operation
django-unfold copied to clipboard

Admin Change Form Page Blank

Open oesah opened this issue 4 months ago • 4 comments

What version of Unfold are you using? 0.40.0

What version of Django are you using?

4.2.16

What browser are you using?

Firefox 131.0.2 and Chrome 129.0.6668.100

Did you checked changelog/commit history, if the bug is not already fixed?

Yes

Did you searched other issues, if the bug is not already fixed?

For example: Yes or No

Did you checked documentation?

Yes

Are you able to replicate the bug in the demo site?

No

Repository with reproduced bug

It's private project, I cannot share the code.

Describe your issue

change_form pages on some models are just blank (white). The console shows:

alpine.js:5 Uncaught TypeError: Cannot read properties of undefined (reading 'startsWith')
    at alpine.js:5:2789
    at fr.reduce.name (alpine.js:5:2935)
    at Array.reduce (<anonymous>)
    at alpine.js:5:2921
    at Array.map (<anonymous>)
    at de (alpine.js:5:2049)
    at alpine.js:5:5151
    at T (alpine.js:5:3875)
    at T (alpine.js:5:3932)
    at T (alpine.js:5:3932)

On some models there is no issue, it only affects some of my models. Here is one example of a model that works:

class SubjectCategory(models.Model):
    description = models.TextField(blank=True, null=True)
    approved = models.BooleanField(default=False)
    name = models.CharField(max_length=256, unique=True)
    created_by = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        related_name="%(app_label)s_%(class)s_created",
        null=True,
        blank=True,
    )
    responsible = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        related_name="%(app_label)s_%(class)s_responsible",
        null=True,
        blank=True,
    )

@admin.register(models.SubjectCategory)
class SubjectCategoryAdmin(unfold_admin.ModelAdmin):
    list_display = ("name", )

Here is a model that does not work:

class Vendor(models.Model):
    url = models.URLField(blank=True, null=True)
    attributes = models.ManyToManyField(
        Attribute,
        blank=True,
        related_name="vendors",
    )
    approved = models.BooleanField(default=False)
    name = models.CharField(max_length=256, unique=True)

@admin.register(models.Vendor)
class VendorAdmin(BaseAdminMixin, unfold_admin.ModelAdmin):
    list_display = ("name", )
    search_fields = ("name", "url")

For some reason, on the second model it does not seem to initiate the JS part properly. I can play around with the html and remove the attribute "x-cloak" and then I see the content, but the JS is not working.

I cannot find anything important that's different in these models or admin config.

oesah avatar Oct 15 '24 12:10 oesah