Auto Focus if validation fails

omojesu 29 Nov, 2008
Hi,
Is it possible to ensure the focus or mouse is on the field that fails validation upon submission in addition to the error tip that is provided? This will make it easier for visitors to know exactly where the error is. Better still, I have seen some forms that will actually change the color of the specific textfields to indicate that the user has to correctly complete that.

Thanks for any code ideas
Max_admin 30 Nov, 2008
Hi omojesu,

the field will be focused actually!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 30 Nov, 2008
Hi omojesu,

If you look here you'll also find a recent post on textareas which may give you ideas for changing field colours.

Bob
Max_admin 12 Jul, 2009
Hi,

the current validation script used doesn't support auto focus, I will add this feature soon!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kidbot 17 Jul, 2009
Good to hear it's in the works. for now I've got a 'hack' that seems to work pretty good.

Replace the massvalidate function in /components/com_chronocontact/js/validationlive_standalone.js with the code below

LiveValidation.massValidate = function(validations){
var returnValue = true;
el = false;

for(var i = 0, len = validations.length; i < len; ++i ){
var valid = validations[i].validate();
if(!valid && !el) el = validations[i].element;
if(returnValue) returnValue = valid;
}
if(!returnValue){
el.scrollIntoView(true);
}
return returnValue;
}

This finds the first validation error and uses scrollIntoView to let the user know their was a problem.

Hope this helps
Max_admin 26 Jul, 2009
Hi, thanks for sharing this, but it didn't work for me, the attached code works but its not very smooth, it needs some improvements and more testing!

LiveValidation.massValidate = function(validations){
  var returnValue = true;
	for(var i = 0, len = validations.length; i < len; ++i ){
		var valid = validations[i].validate();
		if(returnValue) returnValue = valid;
		if(!valid)validations[i].element.focus();
	}
	return returnValue;
}


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
alexpj 11 Apr, 2010
hi,

the script seems to work.

Is there a way to mark the errorbox when it get the focus and show the errormessage (title="xxxxx")

by modding this funktion, the message will not removed on foczus. Maybe the is a better way to improve this....

When more validation errors are in the form, the focus is in the last field. Is is possible to put the focus in the first field?

show the message at focus:
 /**
     *	removes the message and the field class
     */
   /* removeMessageAndFieldClass: function(){
      this.removeMessage();
      this.removeFieldClass();
    }*/
This topic is locked and no more replies can be posted.