So ... the answer is that none of your JS code works because Chrome uses HTML5 input elements, including form validation. So, if you do not fill in the fields correctly, your verification code will never work!
In HTML5, the required attribute is a boolean, either true or false. According to the specification, the browser should fire an invalid event in the problem field. If you want, you can override the default locking behavior at this point. However, your script breaks again where you try attr('required') . It will return true or false in Chrome using HTML5, and not a value like email , as you expect.
So, you need to add these two parts if you want this to work:
$(":input").bind("invalid", function(e){ e.preventDefault();
And then the code refactor from
var a = $(this).attr('required');
be
var a = $(this).attr('required') ? $(this).attr('type') : "";
And change the switch statement to match if necessary
One of the latest ideas . You can also take a really cool approach (aka Feature Detection) and do this instead:
Wrap the inside of the current validate: function as follows:
if(typeof $('<input />')[0].checkValidity === "undefined") { ... existing code .. } else { $(':input').bind('invalid', function(){ $(this).addClass('error'); }).blur(function(){
Here is a demo of the second version, which will work in Chrome and possibly in the current / beta version of Opera.
Doug neiner
source share