Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ENHANCEMENT EmailField now uses type="email" #349

Merged
merged 2 commits into from

5 participants

@halkyon
Owner

This has the benefit of allowing email validation in the browser, when using the required="required" attribute.
If using an old browser, the "email" type will fallback to "text" so it degrades gracefully in old browsers.

halkyon added some commits
@halkyon halkyon ENHANCEMENT EmailField now uses type="email", which has the benefit of
allowing email validation when using the required="required" attribute.
If using an old browser, the "email" type will fallback to "text"
23c3fb8
@halkyon halkyon BUGFIX Ensure merging correctly 80facbd
@wilr wilr merged commit 8f4957a into from
@chillu
Owner

Hmmm, so by extension, we made a decision to use HTML5 by default in form fields? Because this will break validation in XHTML and HTML, right? Seems like a good default, but has broader implications than described here. On the long run, we want doctype-specific templates I guess, but too far away from that at the moment so we have to decide on one. Sean, can you add something to the upgrading docs around "Defaulting to HTML5 output for form fields", and an example on how to revert that? (through setAttribute('type', 'text'))

@wilr
Collaborator

Well we kinda already have made the call to use HTML on the front end. DateField, GridField and I'm sure others all use HTML5 data attributes which I doubt validate.

@spierala

it would be nice to be able to set the type of the email field without subclassing it. if you have a custom form validation then the html5 build in validation of some browsers is rather annoying

@simonwelsh

If you've got custom validation already, why not just use a TextField?

@spierala

I mean the EmailField is good to have server side validation built-in. But for example if you have client side js validation then the html5 default validation is not so useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. @halkyon

    ENHANCEMENT EmailField now uses type="email", which has the benefit of

    halkyon authored
    allowing email validation when using the required="required" attribute.
    If using an old browser, the "email" type will fallback to "text"
  2. @halkyon
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 0 deletions.
  1. +9 −0 forms/EmailField.php
View
9 forms/EmailField.php
@@ -10,6 +10,15 @@ function Type() {
return 'email text';
}
+ function getAttributes() {
+ return array_merge(
+ parent::getAttributes(),
+ array(
+ 'type' => 'email'
+ )
+ );
+ }
+
/**
* Validates for RFC 2822 compliant email adresses.
*
Something went wrong with that request. Please try again.