Opened 11 years ago

Closed 11 years ago

#4020 closed (wontfix)

USPhoneField, USZipCodeField and USSocialSecurityNumberField should implement HTML maxlength

Reported by: joe4444 Owned by: nobody
Component: Forms Version: master
Severity: Keywords: usphonefield uszipcodefield ussocialsecuritynumberfield
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


For a CharField with max_length=30 it is not necessary to set attrs={'maxlength': '30'} in that form's widget (or set a widget at all in many cases). However, the fields USPhoneField, USZipCodeField and USSocialSecurityNumberField do not set maxlength="#" in the HTML they produce. In fact, USZipCodeField explicitly sets max_length=None. Maybe there is a good reason for this, but it seems like these fields could automatically add maxlength="#" to their output considering they validate for a specific length and format.

    phone = forms.USPhoneField(widget=forms.TextInput(attrs={'maxlength': '12'}))    # a bit verbose
    phone = forms.USPhoneField()    # should be equivalent to the previous line

I wish I had a patch for this, but I wouldn't know where to begin.

Change History (4)

comment:1 Changed 11 years ago by joe4444

Also it wouldn't hurt to automatically set size="#" in the HTML since it's easy to override.

comment:2 Changed 11 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 11 years ago by anonymous

maxlength is a pain when you're copy/pasting your info from a file, with dashes or spaces, and the form expects spaceless entry. Then you get an incomplete paste, further wasting the user's time.

comment:4 Changed 11 years ago by Julian Bez

Resolution: wontfix
Status: newclosed

Like anonymous said, it isn't really useful.

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