File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -528,7 +528,7 @@ class JustValidate {
528
528
for ( const fieldName in this . fields ) {
529
529
const field = this . fields [ fieldName ] ;
530
530
if ( ! field . isValid ) {
531
- field . elem . focus ( ) ;
531
+ setTimeout ( ( ) => field . elem . focus ( ) , 0 ) ;
532
532
break ;
533
533
}
534
534
}
@@ -579,12 +579,7 @@ class JustValidate {
579
579
setForm ( form : Element ) {
580
580
this . form = form ;
581
581
this . form . setAttribute ( 'novalidate' , 'novalidate' ) ;
582
- let callbackCalled = false ;
583
582
this . form . addEventListener ( 'submit' , ( ev ) => {
584
- if ( callbackCalled ) {
585
- return ;
586
- }
587
-
588
583
ev . preventDefault ( ) ;
589
584
this . isSubmitted = true ;
590
585
@@ -593,8 +588,6 @@ class JustValidate {
593
588
}
594
589
this . validate ( ) . then ( ( hasPromises ) => {
595
590
if ( this . isValid ) {
596
- ( this . form as HTMLFormElement ) . submit ( ) ;
597
- callbackCalled = true ;
598
591
this . onSuccessCallback ?.( ev ) ;
599
592
}
600
593
@@ -1089,13 +1082,17 @@ class JustValidate {
1089
1082
}
1090
1083
}
1091
1084
1092
- setCurrentLocale ( locale : string ) {
1093
- if ( typeof locale !== 'string' ) {
1085
+ setCurrentLocale ( locale ? : string ) {
1086
+ if ( typeof locale !== 'string' && locale !== undefined ) {
1094
1087
console . error ( 'Current locale should be a string' ) ;
1095
1088
return ;
1096
1089
}
1097
1090
1098
1091
this . currentLocale = locale ;
1092
+
1093
+ if ( this . isSubmitted ) {
1094
+ this . validate ( ) ;
1095
+ }
1099
1096
}
1100
1097
1101
1098
onSuccess ( callback : ( ev ?: Event ) => void ) {
You can’t perform that action at this time.
0 commit comments