@@ -483,25 +483,50 @@ TODO:
483
483
$form . find ( '.nav-tabs a[href="#' + paneId + '"]' ) . tab ( 'show' ) ;
484
484
}
485
485
486
- // Scroll to first error and highlight it
487
- $ ( 'html, body' ) . animate ( {
488
- scrollTop : $firstError . offset ( ) . top - ( $ ( window ) . height ( ) / 2 ) ,
489
- } , {
490
- duration : 'slow' ,
491
- complete : function ( ) {
492
- if ( ! options . skipFocus ) {
493
- $firstError . focus ( ) ;
494
- }
495
- if ( options . elementAttentionClass ) {
496
- $firstError . addClass ( options . elementAttentionClass ) ;
497
- if ( options . removeClassAfter ) {
498
- setTimeout ( function ( ) {
499
- $firstError . removeClass ( options . elementAttentionClass ) ;
500
- } , options . removeClassAfter ) ;
486
+ if ( ! $firstError . is ( ':visible' ) ) {
487
+ // The error is invisible => try to find the error message or field name and display it in alert() instead
488
+ if ( $firstError . find ( 'p.help-block-error' ) . length > 0 ) {
489
+ alert ( 'Configuration error. A field has the following problem but is not visible on the page: ' + $firstError . find ( 'p.help-block-error' ) . html ( ) ) ;
490
+ } else {
491
+ var fieldName ;
492
+ var $label = $firstError . find ( 'label' ) ; //first look for a label
493
+ if ( $label . length > 0 ) {
494
+ fieldName = $label . html ( ) . replace ( / : $ / , '' ) ;
495
+ } else {
496
+ if ( $label . is ( ':input' ) ) { //then look for input name
497
+ fieldName = $label . attr ( 'name' ) ;
498
+ } else if ( $firstError . find ( ':input' ) . length > 0 ) {
499
+ fieldName = $firstError . find ( ':input:first' ) . attr ( 'name' ) ;
500
+ }
501
+ if ( fieldName ) {
502
+ alert ( 'Configuration error. The field ' + fieldName + ' has an error but is not visible on the page.' ) ;
503
+ } else {
504
+ alert ( 'Configuration error. A field has an error but is not visible on the page.' ) ;
501
505
}
502
506
}
507
+ $firstError = $firstError . closest ( ':visible' ) ;
503
508
}
504
- } ) ;
509
+ } else {
510
+ // Scroll to first error and highlight it
511
+ $ ( 'html, body' ) . animate ( {
512
+ scrollTop : $firstError . offset ( ) . top - ( $ ( window ) . height ( ) / 2 ) ,
513
+ } , {
514
+ duration : 'slow' ,
515
+ complete : function ( ) {
516
+ if ( ! options . skipFocus ) {
517
+ $firstError . focus ( ) ;
518
+ }
519
+ if ( options . elementAttentionClass ) {
520
+ $firstError . addClass ( options . elementAttentionClass ) ;
521
+ if ( options . removeClassAfter ) {
522
+ setTimeout ( function ( ) {
523
+ $firstError . removeClass ( options . elementAttentionClass ) ;
524
+ } , options . removeClassAfter ) ;
525
+ }
526
+ }
527
+ }
528
+ } ) ;
529
+ }
505
530
506
531
// Add tooltip on submit button
507
532
if ( ! options . skipSubmitButtonTooltip ) {
0 commit comments