Opened 8 years ago

Closed 8 years ago

#3809 closed (invalid)

Newforms Select widget has (invalid) "maxlength" attribute

Reported by: joe4444 Owned by: adrian
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: UI/UX:

Description

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 8 years ago by joe4444

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 8 years ago by joe4444

Just a typo in my previous reply:

should read attrs= not attr=

comment:3 Changed 8 years ago by SmileyChris

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

comment:4 Changed 8 years ago by SmileyChris

  • Resolution set to invalid
  • Status changed from new to closed

The real reason of your problem is #3810

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