Usability: stripping white space from form fields

605 views
Skip to first unread message

Greg Fuller

unread,
Jul 4, 2008, 3:51:10 AM7/4/08
to Django users
I want to mention what I consider to be a usability issue with Django
forms. It has to do with there being no option to strip leading and
trailing whitespace from CharFields, URLFields, EmailFields, etc.
Ticket #4969 was to address this issue but was closed with as a
'wontfix', and I have seen other discussions on this issue.

As a developer, I know better than to enter spaces in a field, or to
blank an existing entry with spaces. But non-technical users more
often than not do not make this distinction. Here are some
implications of not stripping these fields:

1. It let's the user get past required=True. You can set this behavior
if you go to to admin-->sites, edit the display name by blanking it
out with spaces, and save. The "this field is required" message is
not displayed and the record is saved. Of course technically the
field is not empty, but for all practical purposes it is.

2. An example of an even more serious problem is what happens if you
blank out the domain name field of a site with spaces. Then you
cannot even select the site from the list to edit it. There is no
way to correct the error through normal procedures.

3. In another situation, it causes confusion on field errors.
Consider an email field that is not required, but must be valid if it
is entered. If the user enters an email address, then blanks it out
with spaces, or just leaves one space before saving , he or she will
get an error message to enter a valid email. This is very confusing,
not to developers of course, but to others. They see an error message
to enter a valid email on a field that is not required, and the field
appears to be blank.

4. It also results in unwanted leading and trailing spaces. In most
use cases, you don't want leading or trailing spaces in a char field
and URL field, an email field, etc.

I know this has been discussed before, but I hope this ticket can be
reopened, and that stripping white space can at least be an option.
I'm sure there are use cases where leading and trailing white space is
significant, but in most use cases, not stripping white space causes
usability issues that I feel compelled to address one way or another.

This is not just theoretical - I have seen parallel problems in past
applications during usability testing and with customer support.

Thanks for considering this, and thanks for a great framework !

Karen Tracey

unread,
Jul 4, 2008, 9:42:03 AM7/4/08
to django...@googlegroups.com
On Fri, Jul 4, 2008 at 3:51 AM, Greg Fuller <greg...@gmail.com> wrote:
I want to mention what I consider to be a usability issue with Django
forms.  It has to do with there being no option to strip  leading and
trailing whitespace from CharFields, URLFields, EmailFields, etc.
Ticket #4969 was to address this issue but was closed with as a
'wontfix', and I have seen other discussions on this issue.

I think you mean #4960 (http://code.djangoproject.com/ticket/4960), not #4969.  There is also another ticket opened for this, #6362 (http://code.djangoproject.com/ticket/6362) which is in design decision needed.

I agree that an option to strip leading/trailing wihtespace from form fields would be useful, and is probably more often than not the behavior that is desired by default. 

Karen

Norman Harman

unread,
Jul 7, 2008, 10:33:53 AM7/7/08
to django...@googlegroups.com

It's easier and quicker to locally extend Django.

Here's the start of my forms extension. It has all the form goodness I
want and in my forms.py I do a

from myforms import *


from django import newforms as forms
from django.newforms import ModelForm
from django.newforms.models import ModelChoiceField,
ModelMultipleChoiceField
from django.contrib.localflavor.us.forms import USPhoneNumberField
from django.newforms.fields import *
from django.newforms.widgets import *
import django.newforms.fields
import django.newforms.widgets
__all__ = ["StrippedCharField",]
__all__.extend(["forms", "ModelForm", "ModelChoiceField",
"ModelMultipleChoiceField", "USPhoneNumberField"])
__all__.extend(django.newforms.fields.__all__)
__all__.extend(django.newforms.widgets.__all__)


class StrippedCharField(CharField):
"""Newforms CharField that strips trailing and leading spaces."""
def clean(self, value):
if value is not None:
value = value.strip()
return super(StrippedCharField, self).clean(value)


--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun! Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

Reply all
Reply to author
Forward
0 new messages