Opened 18 years ago
Closed 17 years ago
#3578 closed (fixed)
newforms EmailField takes the wrong max_length when rendered as html and a CharField exists.
Reported by: | Georgi Stanojevski <glisha gmail com> | Owned by: | Allagappan (IRC:vegpuff) |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
If I have a form with CharField and a form with EmailField like bellow. The TextInput widget in the EmailField takes the max_length attribute from the prevous form and displays the input html with a wrong attribute. The validation of the field is OK.
I guess this happens in the TextInput widget, but I can't figure it where on my own to help.
from django import newforms as forms from django.newforms.widgets import * attrs1={'class':'aclass'} class form1(forms.Form): field1 = forms.CharField(widget=TextInput(attrs=attrs1),max_length=30) class form2(forms.Form): field2 = forms.EmailField(widget=TextInput(attrs=attrs1),max_length=10) f2 = form2() f2.as_ul() Out[12]: u'<li><label for="id_field2">Field2:</label> <input id="id_field2" type="text" class="aclass" name="field2" maxlength="30" /></li>' f2 = form2({'field2':'over10@domain.com'}) f2.is_valid() Out[9]: False In [10]: f2.errors Out[10]: {'field2': [u'Ensure this value has at most 10 characters.']
Attachments (1)
Change History (8)
comment:1 by , 18 years ago
Summary: | newforms EmailField takes the wrong maxlength when rendered as html and a CharField exists. → newforms EmailField takes the wrong max_length when rendered as html and a CharField exists. |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
Has patch: | set |
---|
comment:3 by , 17 years ago
Opps, I have a typo and the key max_length
in the dict that is being returned should be maxlength
.
comment:4 by , 17 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
follow-up: 6 comment:5 by , 17 years ago
Could this have been fixed already in some past changes to RegexField/URLField/EmailField ? I tried duplicating it just now and can't do it
>>> from django import newforms as forms >>> >>> attrs1={'class':'aclass'} >>> >>> class form1(forms.Form): ... field1 = forms.CharField(widget=forms.TextInput(attrs=attrs1),max_length=30) ... >>> class form2(forms.Form): ... field2 = forms.EmailField(widget=forms.TextInput(attrs=attrs1),max_length=10) ... >>> f = form2() >>> f.as_ul() u'<li><label for="id_field2">Field2:</label> <input id="id_field2" type="text" class="aclass" name="field2" maxlength="10" /></li>'
comment:6 by , 17 years ago
Owner: | changed from | to
---|
Yeah. It WFM. Closing the ticket.
>>> from django import newforms as forms >>> from django.newforms.widgets import * >>> attrs1={'class':'aclass'} >>> class form1(forms.Form): ... field1 = forms.CharField(widget=TextInput(attrs=attrs1),max_length=30) ... >>> class form2(forms.Form): ... field2 = forms.EmailField(widget=TextInput(attrs=attrs1),max_length=10) ... >>> f2= form2() >>> f2.as_ul() u'<li><label for="id_field2">Field2:</label> <input id="id_field2" type="text" class="aclass" name="field2" maxlength="10" /></li>' >>> f2=form2({'field2':'over10@domain.com'}) >>> f2.is_valid() False >>> f2.errors {}
comment:7 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Confirmed.