Skip to content

Cannot use textarea as subwidget_form #202

@jywsn

Description

@jywsn
  • Django better admin ArrayField version: 1.4.2
  • Django version: 3.2.13
  • Python version: 3.7.13
  • Operating System: Mac OS 12.3.1

Description

I want to pass a custom subwidget_form to DynamicArrayWidget. Specifically, I want to use forms.TextAreainstead of forms.TextInput:

class MyModelAdmin(...):
    ...
    form = modelform_factory(
        ...
        widgets =  {
            "my_field_name": DynamicArrayWidget(subwidget_form=forms.Textarea),
        }
     )

When I do this, clicking on the "Add another" button throws a JS error:

django_better_admin_arrayfield.min.js:1 Uncaught TypeError: Cannot read properties of null (reading 'getAttribute')
    at HTMLInputElement.<anonymous> (django_better_admin_arrayfield.min.js:1:474)
(anonymous) @ django_better_admin_arrayfield.min.js:1

...because of this line:
https://github.com/gradam/django-better-admin-arrayfield/blob/master/django_better_admin_arrayfield/static/js/django_better_admin_arrayfield.js#L29

...because the querySelector is specifically looking for an input (not a textarea).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions