Opened 10 years ago

Closed 9 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: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

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)

3578_newforms_emailfield_maxlength_fix.diff (571 bytes) - added by Brian Rosner <brosner@…> 9 years ago.
patch to fix #3578

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by Simon G. <dev@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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: UnreviewedAccepted

Confirmed.

Changed 9 years ago by Brian Rosner <brosner@…>

patch to fix #3578

comment:2 Changed 9 years ago by Brian Rosner <brosner@…>

Has patch: set

comment:3 Changed 9 years ago by Brian Rosner <brosner@…>

Opps, I have a typo and the key max_length in the dict that is being returned should be maxlength .

comment:4 Changed 9 years ago by Chris Beaven

Needs tests: set
Patch needs improvement: set

comment:5 Changed 9 years ago by Collin Grady <cgrady@…>

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 in reply to:  5 Changed 9 years ago by Allagappan (IRC:vegpuff)

Owner: changed from nobody to Allagappan (IRC:vegpuff)

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 Changed 9 years ago by Allagappan (IRC:vegpuff)

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top