livevalidation icon indicating copy to clipboard operation
livevalidation copied to clipboard

Focus On Errored Input

Open ScottBaxter1 opened this issue 11 years ago • 1 comments

Hi Guys,

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

Hope this makes sense.

ScottBaxter1 avatar Feb 12 '14 15:02 ScottBaxter1

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();
 }
 },

ScottBaxter1 avatar Feb 12 '14 17:02 ScottBaxter1