Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayField and ArrayWidget Rendering problem #825

Open
ZairMahmood opened this issue Oct 23, 2024 · 1 comment
Open

ArrayField and ArrayWidget Rendering problem #825

ZairMahmood opened this issue Oct 23, 2024 · 1 comment

Comments

@ZairMahmood
Copy link

What version of Unfold are you using?

0.40.0

What version of Django are you using?

5.1

What browser are you using?

Chrome 128

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?

Yes

Did you checked documentation?

Yes

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

ArrayWidget is not used in the demo site

Repository with reproduced bug

model code:

from django.contrib.postgres.fields import ArrayField
from django.db import models

class Customer(models.Model):
    notes = ArrayField(m.TextField(), default=list, blank=True, verbose_name='Notes')

admin code:

class CustomerInline(ModelAdmin):
    model = Customer
    extra = 1
    fields = ['notes']
    formfield_overrides = {
        ArrayField: {
            "widget": ArrayWidget,
        },
    }

Describe your issue

When adding in the following items to the array field using the widget:

- Something 1
- Something 2, Something 3
- Something 4

It saves properly in the backend as:
['Something 1', 'Something 2, Something 3', 'Something 4']

but when the page reloads, it renders as:

- Something 1
- Something 2
-  Something 3
- Something 4

Notice the extra space before Something 3 also

@ZairMahmood
Copy link
Author

After much investigation this is what I found:
The issue arises from:
https://github.com/django/django/blob/main/django/contrib/postgres/forms/array.py#L38-L41
For now, I monkeypatched this in my application to just return value instead of converting it to a string and this fixed the issue.

I think we need a way to define the delimiter when using ArrayWidget. I tried a few things like SimpleArrayField(forms.CharField(), delimiter='|', widget=ArrayWidget) but it produced funky results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant