3
I have a very long form and would like to click on Ubmit and the field is in error, that the page can scroll (jQuery) to this field so that the person knows exactly what is wrong. I started out that way:
$("#sdEmpresa").removeClass("hidden").css("border", "1px dashed red");
So I was able to speed this up:
if(empresa == ""){
// callback method use this space how you like
var body = $("html, body");
body.animate({scrollTop:0}, 1500, function(){
$("#sdEmpresa").removeClass("hidden").css("border", "1px dashed red");
});
}
Here he goes back to his body, like back to #sdEmpresa
?
don’t need to use
body.animate
, just give Focus in the field. It will be difficult to give a more complete answer because each field has a rule... Ever thought of using some plugin for validation?– Papa Charlie
I even thought @Papacharlie but my validations are very specific, but could you put this modified code so that the scroll goes over the field? Learning jQuery (rsrsr)
– Marcos Vinicius
Generally plugins have a vast rule of validation... I recommend taking a look at at least. I didn’t get the end of the comment, you want me to give an example of Focus?
– Papa Charlie
If you can, I’d be grateful to see how that code could work the way I seek.
– Marcos Vinicius
Use
$('#sdEmpresa').focus();
– Papa Charlie