Skip to content

Commit

Permalink
Support area codes updating selected flag in national format
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Dec 7, 2024
1 parent 5313e92 commit a7427cc
Show file tree
Hide file tree
Showing 20 changed files with 1,515 additions and 1,224 deletions.
47 changes: 33 additions & 14 deletions build/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ var factoryOutput = (() => {
"au",
// Australia
"61",
0
0,
null,
"0"
],
[
"at",
Expand Down Expand Up @@ -295,14 +297,16 @@ var factoryOutput = (() => {
// Christmas Island
"61",
2,
["89164"]
["89164"],
"0"
],
[
"cc",
// Cocos (Keeling) Islands
"61",
1,
["89162"]
["89162"],
"0"
],
[
"co",
Expand Down Expand Up @@ -535,7 +539,8 @@ var factoryOutput = (() => {
// Guernsey
"44",
1,
["1481", "7781", "7839", "7911"]
["1481", "7781", "7839", "7911"],
"0"
],
[
"gn",
Expand Down Expand Up @@ -607,7 +612,8 @@ var factoryOutput = (() => {
// Isle of Man
"44",
2,
["1624", "74576", "7524", "7924", "7624"]
["1624", "74576", "7524", "7924", "7624"],
"0"
],
[
"il",
Expand Down Expand Up @@ -637,7 +643,8 @@ var factoryOutput = (() => {
// Jersey
"44",
3,
["1534", "7509", "7700", "7797", "7829", "7937"]
["1534", "7509", "7700", "7797", "7829", "7937"],
"0"
],
[
"jo",
Expand All @@ -649,7 +656,8 @@ var factoryOutput = (() => {
// Kazakhstan
"7",
1,
["33", "7"]
["33", "7"],
"8"
],
[
"ke",
Expand Down Expand Up @@ -781,7 +789,8 @@ var factoryOutput = (() => {
// Mayotte
"262",
1,
["269", "639"]
["269", "639"],
"0"
],
[
"mx",
Expand Down Expand Up @@ -824,7 +833,9 @@ var factoryOutput = (() => {
"ma",
// Morocco
"212",
0
0,
null,
"0"
],
[
"mz",
Expand Down Expand Up @@ -985,7 +996,9 @@ var factoryOutput = (() => {
"re",
// Réunion
"262",
0
0,
null,
"0"
],
[
"ro",
Expand All @@ -996,7 +1009,9 @@ var factoryOutput = (() => {
"ru",
// Russia
"7",
0
0,
null,
"8"
],
[
"rw",
Expand Down Expand Up @@ -1268,7 +1283,9 @@ var factoryOutput = (() => {
"gb",
// United Kingdom
"44",
0
0,
null,
"0"
],
[
"us",
Expand Down Expand Up @@ -1325,7 +1342,8 @@ var factoryOutput = (() => {
// Western Sahara
"212",
1,
["5288", "5289"]
["5288", "5289"],
"0"
],
[
"ye",
Expand Down Expand Up @@ -1354,7 +1372,8 @@ var factoryOutput = (() => {
priority: c[2] || 0,
areaCodes: c[3] || null,
partialAreaCodes: null,
nodeById: {}
nodeById: {},
nationalPrefix: c[4] || null
};
}
var data_default = allCountries;
Expand Down
2 changes: 1 addition & 1 deletion build/js/data.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions build/js/intlTelInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module "intl-tel-input/data" {
areaCodes: string[] | null;
partialAreaCodes: string[] | null;
nodeById: object;
nationalPrefix: string | null;
};
const allCountries: Country[];
export default allCountries;
Expand Down Expand Up @@ -331,6 +332,7 @@ declare module "intl-tel-input" {
dialCode?: string;
areaCodes?: string[];
partialAreaCodes?: string[];
nationalPrefix?: string;
};
interface AllOptions {
allowDropdown: boolean;
Expand Down Expand Up @@ -442,6 +444,7 @@ declare module "intl-tel-input" {
private _updateValFromNumber;
private _updateCountryFromNumber;
private _isAreaCodeMatch;
private _ensureHasDialCode;
private _getCountryFromNumber;
private _highlightListItem;
private _getCountryData;
Expand Down
68 changes: 44 additions & 24 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ var factoryOutput = (() => {
"au",
// Australia
"61",
0
0,
null,
"0"
],
[
"at",
Expand Down Expand Up @@ -298,14 +300,16 @@ var factoryOutput = (() => {
// Christmas Island
"61",
2,
["89164"]
["89164"],
"0"
],
[
"cc",
// Cocos (Keeling) Islands
"61",
1,
["89162"]
["89162"],
"0"
],
[
"co",
Expand Down Expand Up @@ -538,7 +542,8 @@ var factoryOutput = (() => {
// Guernsey
"44",
1,
["1481", "7781", "7839", "7911"]
["1481", "7781", "7839", "7911"],
"0"
],
[
"gn",
Expand Down Expand Up @@ -610,7 +615,8 @@ var factoryOutput = (() => {
// Isle of Man
"44",
2,
["1624", "74576", "7524", "7924", "7624"]
["1624", "74576", "7524", "7924", "7624"],
"0"
],
[
"il",
Expand Down Expand Up @@ -640,7 +646,8 @@ var factoryOutput = (() => {
// Jersey
"44",
3,
["1534", "7509", "7700", "7797", "7829", "7937"]
["1534", "7509", "7700", "7797", "7829", "7937"],
"0"
],
[
"jo",
Expand All @@ -652,7 +659,8 @@ var factoryOutput = (() => {
// Kazakhstan
"7",
1,
["33", "7"]
["33", "7"],
"8"
],
[
"ke",
Expand Down Expand Up @@ -784,7 +792,8 @@ var factoryOutput = (() => {
// Mayotte
"262",
1,
["269", "639"]
["269", "639"],
"0"
],
[
"mx",
Expand Down Expand Up @@ -827,7 +836,9 @@ var factoryOutput = (() => {
"ma",
// Morocco
"212",
0
0,
null,
"0"
],
[
"mz",
Expand Down Expand Up @@ -988,7 +999,9 @@ var factoryOutput = (() => {
"re",
// Réunion
"262",
0
0,
null,
"0"
],
[
"ro",
Expand All @@ -999,7 +1012,9 @@ var factoryOutput = (() => {
"ru",
// Russia
"7",
0
0,
null,
"8"
],
[
"rw",
Expand Down Expand Up @@ -1271,7 +1286,9 @@ var factoryOutput = (() => {
"gb",
// United Kingdom
"44",
0
0,
null,
"0"
],
[
"us",
Expand Down Expand Up @@ -1328,7 +1345,8 @@ var factoryOutput = (() => {
// Western Sahara
"212",
1,
["5288", "5289"]
["5288", "5289"],
"0"
],
[
"ye",
Expand Down Expand Up @@ -1357,7 +1375,8 @@ var factoryOutput = (() => {
priority: c[2] || 0,
areaCodes: c[3] || null,
partialAreaCodes: null,
nodeById: {}
nodeById: {},
nationalPrefix: c[4] || null
};
}
var data_default = allCountries;
Expand Down Expand Up @@ -2580,20 +2599,21 @@ var factoryOutput = (() => {
}
return false;
}
_ensureHasDialCode(number) {
const { dialCode, nationalPrefix } = this.selectedCountryData;
const alreadyHasPlus = number.charAt(0) === "+";
if (alreadyHasPlus || !dialCode) {
return number;
}
const hasPrefix = nationalPrefix && number.charAt(0) === nationalPrefix;
const cleanNumber = hasPrefix ? number.substring(1) : number;
return `+${dialCode}${cleanNumber}`;
}
_getCountryFromNumber(fullNumber) {
const plusIndex = fullNumber.indexOf("+");
let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
const selectedDialCode = this.selectedCountryData.dialCode;
const isNanp = selectedDialCode === "1";
if (number && isNanp && number.charAt(0) !== "+") {
if (number.charAt(0) !== "1") {
number = `1${number}`;
}
number = `+${number}`;
}
if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
number = `+${selectedDialCode}${number}`;
}
number = this._ensureHasDialCode(number);
const dialCode = this._getDialCode(number, true);
const numeric = getNumeric(number);
if (dialCode) {
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit a7427cc

Please sign in to comment.