#34257: ForeignKeyRawIdWidget doesn't include vForeignKeyRawIdAdminField class
when
custom class passed in attrs
-------------------------------------+-------------------------------------
Reporter: Kevin | Owner: nobody
Marsh |
Type: Bug | Status: new
Component: | Version: dev
contrib.admin | Keywords:
Severity: Normal | widget,admin,raw_id_fields
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I had a situation where I wanted to add an extra class to the
`ForeignKeyRawIdWidget` widget. I noticed that doing something like:
{{{
attrs = {"class": "myAdditionalClass"}
widget = ForeignKeyRawIdWidget(rel, admin_site, attrs=attrs)
}}}
resulted in the widget not having the required
`vForeignKeyRawIdAdminField` class since under the hood
`ForeignKeyRawIdWidget.get_context` does something ''like:''
{{{
context["widget"]["attrs"].setdefault("class",
"vForeignKeyRawIdAdminField")
}}}
meaning the rendered `<input />` looks like:
{{{
<input class="myAdditionalClass" ...
}}}
instead of:
{{{
<input class="myAdditionalClass vForeignKeyRawIdAdminField" ...
}}}
----
Note that this same issue applies to the `ManyToManyRawIdWidget` and
corresponding `vManyToManyRawIdAdminField` class.
----
I'm not sure if `ForeignKeyRawIdWidget`/`ManyToManyRawIdWidget` is meant
to be public, but it'd be nice if we could resolve this in the source.
Currently I can work around this by simply doing:
{{{
attrs = {"class": "myAdditionalClass vForeignKeyRawIdAdminField"}
widget = ForeignKeyRawIdWidget(rel, admin_site, attrs=attrs)
}}}
I can create a PR based on a similar solution in the patch (and also fix
`ManyToManyRawIdWidget`) if this gets accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/34257>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185ad41a6e9-b1a47cf0-a9c6-4e9a-9e46-0bd2b514dd5a-000000%40eu-central-1.amazonses.com.