Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Last active January 4, 2016 05:59
Show Gist options
  • Save westonwatson/8578491 to your computer and use it in GitHub Desktop.
Save westonwatson/8578491 to your computer and use it in GitHub Desktop.
Basic HTML5 Input (placeholder and required) Polyfill/Shim Loader using Modernizr.
//defer until Modernizr is loaded.
$(function () {
/* HTML5 Input Placeholder Polyfill. */
Modernizr.load({
test: Modernizr.input.placeholder,
nope: [
'/assets/css/placeholder_polyfill.min.css',
'/assets/js/placeholder_polyfill.jquery.min.combo.js'
]
});
/* Basic HTML5 Input Validation Polyfill.
* right now, we're only testing for required. if more
* HTML5 goodness is used, additional yepnope testers
* may be required. the library below covers multiple
* features, Check out http://ericleads.com/h5validate/
*/
Modernizr.load({
test: Modernizr.input.required,
nope: [
'/assets/js/jquery.h5validate.js'
]
});
});
//initialize h5Validation polyfill
$(document).ready(function () {
//make sure h5Validate is loaded properly
if (typeof jQuery.h5Validate != 'undefined') $('form').h5Validate({
//custom error CSS class to use for "required" inputs
errorClass: "required_field"
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment