Opened 12 years ago

Closed 12 years ago

#3809 closed (invalid)

Newforms Select widget has (invalid) "maxlength" attribute

Reported by: joe4444 Owned by: Adrian Holovaty
Component: Forms Version: master
Severity: Keywords: newforms select widget maxlength valid html
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


It seems that by default the Select widget produces a tag like this:

<select id="id_status" name="status" maxlength="30">

That causes an HTML validation error due to the maxlength="30" part.

Change History (4)

comment:1 Changed 12 years ago by joe4444

I did a few more tests, and the widget does not produce this output by default. However, when applying attributes as follows, for some reason the maxlength="30" gets added.

req = {'class': 'required'}


    status = forms.ChoiceField(choices=MY_CHOICES, widget=forms.Select(attr=req))

What does not make sense to me is that, although the following should be identical to the previous, it does not produce the same bug:

    status = forms.ChoiceField(choices=MY_CHOICES, widget=forms.Select(attr={'class': 'required'}))

Of course, the former is much more convenient, so it would be preferable if not for the strange HTML bug.

I do not think this is limited to select widgets, but I have not tested others yet.

comment:2 Changed 12 years ago by joe4444

Just a typo in my previous reply:

should read attrs= not attr=

comment:3 Changed 12 years ago by Chris Beaven

Looks like the real bug here is that the attrs dict you're passing gets modified by an internal method.

comment:4 Changed 12 years ago by Chris Beaven

Resolution: invalid
Status: newclosed

The real reason of your problem is #3810

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