jQuery Validation Plugin Mobile Safari focus fix

Date: Mar 11 2015

Anyone using Jquery Validation plugin knows the the focus() does not play nice with mobile safari. Here is the fix to make your apps focus on the field that is not valid when jQuery validation processes.

Just add this handler to your validate method

invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var stid = validator.errorList[0].element.id
var offset = ( $(“#”+stid ).offset().top – 60 );
$(window).scrollTop( offset );
}
}

Be Sociable, Share!

facebook comments:

Leave a Reply