Skip to content

Commit 0e26d98

Browse files
committed
fix #256: set position for phone number widget with default country
1 parent 266c584 commit 0e26d98

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

client/django-formset/PhoneNumber.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,21 @@ class PhoneNumberField {
280280

281281
private updateInputField(phoneNumber: string) {
282282
let caretPosition = this.getCaretPosition();
283+
let isFirst = false;
283284
if (this.editField.innerText.length === caretPosition) {
285+
isFirst = caretPosition === 1;
284286
++caretPosition;
285287
}
286288
this.asYouType.reset();
287289
this.asYouType.input(phoneNumber);
288-
this.inputElement.value = this.asYouType.getChars() === '+' ? '+' : this.asYouType.getNumberValue() ?? '';
290+
if (this.asYouType.getChars() === '+') {
291+
this.inputElement.value = '+';
292+
} else {
293+
this.inputElement.value = this.asYouType.getNumberValue() ?? '';
294+
if (isFirst && this.defaultCountryCode) {
295+
caretPosition = this.editField.innerText.length;
296+
}
297+
}
289298
this.setCaretPosition(caretPosition);
290299
this.inputElement.dispatchEvent(new Event('input'));
291300
}

0 commit comments

Comments
 (0)