Skip to content

Commit b0cd51c

Browse files
committed
fix(): improve switching languages, fix focus field
1 parent c96489f commit b0cd51c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/main.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ class JustValidate {
528528
for (const fieldName in this.fields) {
529529
const field = this.fields[fieldName];
530530
if (!field.isValid) {
531-
field.elem.focus();
531+
setTimeout(() => field.elem.focus(), 0);
532532
break;
533533
}
534534
}
@@ -579,12 +579,7 @@ class JustValidate {
579579
setForm(form: Element) {
580580
this.form = form;
581581
this.form.setAttribute('novalidate', 'novalidate');
582-
let callbackCalled = false;
583582
this.form.addEventListener('submit', (ev) => {
584-
if (callbackCalled) {
585-
return;
586-
}
587-
588583
ev.preventDefault();
589584
this.isSubmitted = true;
590585

@@ -593,8 +588,6 @@ class JustValidate {
593588
}
594589
this.validate().then((hasPromises) => {
595590
if (this.isValid) {
596-
(this.form as HTMLFormElement).submit();
597-
callbackCalled = true;
598591
this.onSuccessCallback?.(ev);
599592
}
600593

@@ -1089,13 +1082,17 @@ class JustValidate {
10891082
}
10901083
}
10911084

1092-
setCurrentLocale(locale: string) {
1093-
if (typeof locale !== 'string') {
1085+
setCurrentLocale(locale?: string) {
1086+
if (typeof locale !== 'string' && locale !== undefined) {
10941087
console.error('Current locale should be a string');
10951088
return;
10961089
}
10971090

10981091
this.currentLocale = locale;
1092+
1093+
if (this.isSubmitted) {
1094+
this.validate();
1095+
}
10991096
}
11001097

11011098
onSuccess(callback: (ev?: Event) => void) {

0 commit comments

Comments
 (0)