Hello all,
Since Django 1.6, the Django form fields for URLs, numbers and email addresses make use of widgets that use type-specific input fields in their HTML rendering. So instead of rendering them as <input type="text">, they now have type="url", type="number" and type="email". This has upsides: for example, an email field will cause an iPhone to display the email-optimized keyboard.
However, in #23075[1] sehmaschine raised an important issue: this also causes browsers to apply their own validation to these fields. This causes a number of issues:
* The validation code used by the browser may not match that used in Django. For example, URLField will accept "
example.com", but Chrome's validation for type="url" will reject it. Safari on the other hand, does accept it. So there are two validation steps, which may not be equal, and which may differ per browser.
* Error behaviour of browsers is inconsistent. Chrome renders it's own unstylable error message. Safari, according to comment 3, will simply remove invalid values, which is a usability disaster in itself, but avoidable if the field was type="text" as then the form validation would detect the invalid value, reject it, and provide a proper error message.
* Validation timing becomes inconsistent. In the traditional form validation flow, the user would submit the form, see any errors, and submit again. With these fields, some of the validation happens before submit, but some does not. This can be confusing for users.
The workaround is to override the widget in ModelForms or admin forms, and force it to forms.TextInput().
If we leave the situation as is, developers may unexpectedly find that their users may get validation errors which are different from all others in content, style and timing (and possibly language), whose criteria do not match other validation steps for the same data, and all this will work differently in different browsers. With the Safari behaviour of simply ignoring invalid values, mentioned by sehmaschine in the ticket, this becomes even more serious.
Therefore, as much as I like using the correct field types, I think their issues outweigh the current benefits. I propose that we change all relevant fields to use forms.TextInput() as their default widget, still allowing a developer to override this with a specific widget if they do want to use type="number". Ideally, considering the potential impact, I'd still like to see this changed in 1.7, although I realise it's very very late for that.
In any case, I thought this might be controversial enough to first bring it up on this list.
cheers,
Erik
[1]
https://code.djangoproject.com/ticket/23075