简体   繁体   中英

Javascript lose focus on first invalid field (jQuery Validation) when labels 'display:block'

Javascript lose focus on first invalid field on 'unhighlight' event (jQuery Validation) when error messages (labels) 'display:block'.

I use pure code from latest jQuery Validation: jquerycom/Plugins/Validation

body {padding:20px;}
/*label.error {display:block;}*/
label.error {color:red;}
p {padding-bottom:15px;}

Code: http://jsfiddle.net/352TH/3/

  1. My error labels are 'inline' in css.
  2. Push Submit button -> two errors are shown, focus on email field.
  3. Write valid email into email field.
  4. Push Submit button -> one error is shown, focus on comment field.

Now just uncommented /*label.error { display:block; }*/ /*label.error { display:block; }*/ line in css code

body {padding:20px;}
label.error {display:block;}
label.error {color:red;}
p {padding-bottom:15px;}

Code: http://jsfiddle.net/352TH/4/

  1. My error labels are 'display:block' in css.
  2. Push Submit button -> two errors are shown, focus on email field.
  3. Write valid email into email field.
  4. Push Submit button -> one error is shown, NO focus on comment field.

:(

Try this

Your code

$(function(){
$("#commentForm").validate({
    errorLabelContainer: '.validationSummary'
});

});

change for

$("#commentForm").validate(function(){
    errorLabelContainer: '.validationSummary'
});

And see this Example

Greetings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM