Opened 7 years ago

Closed 6 years ago

#29045 closed Bug (fixed)

admin CSS overrides Select/SelectMultiple size attribute

Reported by: Jonah Bishop Owned by: Jonah Bishop
Component: contrib.admin Version: 1.11
Severity: Normal Keywords:
Cc: elky Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jonah Bishop)

I have an admin page set up for a model like so:

@admin.register(p_models.ScheduleType)
class ScheduleTypeAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ManyToManyField: {'widget': forms.SelectMultiple(attrs={'size': '30'})},
    }

    list_display = ('name',)

The resulting ManyToMany field has the size attribute set properly, but every browser I try only shows about 8 rows (not 30, as I instructed). I've cleared cache, and tried in multiple browsers (Chrome 63, Firefox 57). My site uses Django 1.11.9.

It looks like the CSS style rules are overriding the size attribute. I'm guessing adding a height: auto; rule to the select[multiple] style set would fix it (it appears to do so in Chrome, at least).

Change History (5)

comment:1 by Jonah Bishop, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Cc: elky added
Summary: Multiple select widget does not honor size attributeadmin CSS overrides Select/SelectMultiple size attribute
Triage Stage: UnreviewedAccepted

comment:3 by Jonah Bishop, 6 years ago

Owner: changed from nobody to Jonah Bishop
Status: newassigned

comment:4 by Jonah Bishop, 6 years ago

Has patch: set

I've added a pull request (https://github.com/django/django/pull/10169) with a small patch to fix this issue. The fix was quite simple: a new "height: auto;" rule for the select[multiple] style case.

comment:5 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 263e0394:

Fixed #29045 -- Fixed admin CSS so that select multiple elements honor the HTML size attribute.

Note: See TracTickets for help on using tickets.
Back to Top