Skip to content

Instantly share code, notes, and snippets.

@tyrauber
Created September 16, 2015 23:18
Show Gist options
  • Save tyrauber/5de42bf4f66c4084b99e to your computer and use it in GitHub Desktop.
Save tyrauber/5de42bf4f66c4084b99e to your computer and use it in GitHub Desktop.
HTML5 Safari Form Validation Polyfill
validate_form = ->
$('form').submit (event) ->
$.each $(this).find('input'), (i,el) ->
validate_field(el);
$(el).on 'blur', -> validate_field(el) ;
window.validate_form = validate_form
validate_field = (el) ->
if ($(el)[0].checkValidity())
$(el).removeClass('validation-error');
else
$(el).addClass('validation-error');
validate_form();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment