Skip to content

Commit

Permalink
Fix strictMode issue: type max len number, select all, can't type 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed May 12, 2024
1 parent 9bb2c9a commit fef25d9
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 11 deletions.
4 changes: 3 additions & 1 deletion build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,9 @@ var factoryOutput = (() => {
const fullNumber = this._getFullNumber();
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
if (!isAllowedChar || hasReachedMaxLength) {
const selectedText = this.telInput.value.substring(this.telInput.selectionStart, this.telInput.selectionEnd);
const hasSelectedDigit = /\d/.test(selectedText);
if (!isAllowedChar || hasReachedMaxLength && !hasSelectedDigit) {
e.preventDefault();
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion build/js/intlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,9 @@ var factoryOutput = (() => {
const fullNumber = this._getFullNumber();
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
if (!isAllowedChar || hasReachedMaxLength) {
const selectedText = this.telInput.value.substring(this.telInput.selectionStart, this.telInput.selectionEnd);
const hasSelectedDigit = /\d/.test(selectedText);
if (!isAllowedChar || hasReachedMaxLength && !hasSelectedDigit) {
e.preventDefault();
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInputWithUtils.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInput.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInputWithUtils.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion react/build/IntlTelInputWithUtils.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion react/demo/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25578,7 +25578,9 @@
const fullNumber = this._getFullNumber();
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
if (!isAllowedChar || hasReachedMaxLength) {
const selectedText = this.telInput.value.substring(this.telInput.selectionStart, this.telInput.selectionEnd);
const hasSelectedDigit = /\d/.test(selectedText);
if (!isAllowedChar || hasReachedMaxLength && !hasSelectedDigit) {
e.preventDefault();
}
}
Expand Down
4 changes: 3 additions & 1 deletion react/demo/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25578,7 +25578,9 @@
const fullNumber = this._getFullNumber();
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
if (!isAllowedChar || hasReachedMaxLength) {
const selectedText = this.telInput.value.substring(this.telInput.selectionStart, this.telInput.selectionEnd);
const hasSelectedDigit = /\d/.test(selectedText);
if (!isAllowedChar || hasReachedMaxLength && !hasSelectedDigit) {
e.preventDefault();
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/js/intl-tel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,10 @@ export class Iti {
const fullNumber = this._getFullNumber();
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
if (!isAllowedChar || hasReachedMaxLength) {
const selectedText = this.telInput.value.substring(this.telInput.selectionStart, this.telInput.selectionEnd);
const hasSelectedDigit = /\d/.test(selectedText);
// ignore the char if (1) it's not an allowed char, or (2) the input has reached max length and no digit is selected (which will be replaced by the new char)
if (!isAllowedChar || (hasReachedMaxLength && !hasSelectedDigit)) {
e.preventDefault();
}
}
Expand Down

0 comments on commit fef25d9

Please sign in to comment.