alechill / livevalidation

Open source javascript library for slick, powerful, and easy client-side validation.
http://livevalidation.com
Other
151 stars 57 forks source link

Focus On Errored Input #18

Open ScottBaxter1 opened 10 years ago

ScottBaxter1 commented 10 years ago

Hi Guys,

If validaiton fails, is it possible for it to focus on the failed input?

Hope this makes sense.

ScottBaxter1 commented 10 years ago

I've managed to do this..

I've just altered the addFieldClass function, with the following:

addFieldClass: function(){

this.removeFieldClass();
if(!this.validationFailed){
if(this.displayMessageWhenEmpty || this.element.value != ''){
    if(this.element.className.indexOf(this.validFieldClass) == -1) this.element.className += ' ' + this.validFieldClass;
}
}else{
if(this.element.className.indexOf(this.invalidFieldClass) == -1) this.element.className += ' ' + this.invalidFieldClass;

  //Set Focus On In-Valid Elements
  var id = this.element.id;
  document.getElementById(id).focus();
 }
 },