Despite all of the buzz around html5 forms, it seems to me like you are creating extra work, in most scenarios, by going this route.
Take, for example, a datepicker field. The native html5 implementation of this renders differently in every browser. In addition your polyfilled solution (jquery UI for instance), for a browser not supporting this feature, will also render differently.
Now, we have introduced multiple points of customization and maintenance for the same form, when we had a perfectly working and unified solution with jquery!
I'd love to hear about some real world experiences in this area, because I'm getting annoyed with all of the buzz!
First of all I'm the creator of webshims lib (one of those polyfills, which isn't maintained anymore). To answer your question:
No, it is really hard to do this just for one project. Well, I have done it, simply because I want to use modern technologies.
Yes absolutely! And here is why:
After including webshims and scripting the following:
//polyfill forms (constraint validation) and forms-ext (date, range etc.)
$.webshims.polyfill('forms forms-ext');
You can simply write your widgets and your constraints into your form:
<input type="date" />
<input type="date" min="2012-10-11" max="2111-01-01" />
<input type="range" disabled />
<input type="email" required placeholder="Yo you can use a placeholder" />
This will create 3 different widgets and each are configured differently. No extra JS needed just standardized, clean and lean code.
Same goes to the DOM API. Here are just two examples: Combining two date fields and combining a range field with a date field.
Degrades gracefully in old browsers and works well in modern ones.
Especially good for mobile (iOS 5, Blackberry have support for date for example)
Better mobile UX (better input UI for touch, better performance, fits to the system), if you are using it: type="email", type="number" and type="date"/type="range"
I'm a developer in a bigger agency and you are absolutely right most clients and most designers won't tolerate much differences, but I still want to use modern technologies, which means webshims lib can give you the best of both worlds.
The polyfilling part
//polyfill constraint validation
$.webshims.polyfill('forms');
Customizing the UI for the error-bubble:
//on DOM-ready
$(function(){
$('form').bind('firstinvalid', function(e){
//show the invalid alert for first invalid element
$.webshims.validityAlert.showFor( e.target );
//prevent browser from showing native validation message
return false;
});
});
generates the following markup:
<!-- the JS code above will generate the following custom styleable HTML markup for the validation alert -->
<span class="validity-alert-wrapper" role="alert">
<span class="validity-alert">
<span class="va-arrow"><span class="va-arrow-box"></span></span>
<span class="va-box">Error message of the current field</span>
</span>
</span>
Customizing the style of an invalid/valid form field:
.form-ui-invalid {
border-color: red;
}
.form-ui-valid {
border-color: green;
}
Customizing the text of the validity alert:
<input required data-errormessage="Hey this is required!!!" />
And now, what's the point:
No problem:
//configure webshims to use customizable widget UI in all browsers
$.webshims.setOptions('forms-ext', {
replaceUI: true
});
$.webshims.polyfill('forms forms-ext');
And also here:
And now, here comes the best:
//configure webshims to use customizable widget UI in all non mobile browsers, but a customizable one in all desktop and all non-capable mobile browsers
$.webshims.setOptions('forms-ext', {
//oh, I know this is bad browser sniffing :-(
replaceUI: !(/mobile|ipad|iphone|fennec|android/i.test(navigator.userAgent))
});
$.webshims.polyfill('forms forms-ext');