intl-tel-input 19.2.20 → 19.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24290,23 +24290,23 @@ var import_client = __toESM(require_client());
24290
24290
  // react/build/IntlTelInput.esm.js
24291
24291
  var import_react = __toESM(require_react());
24292
24292
  var import_prop_types = __toESM(require_prop_types());
24293
- var Z = Object.create;
24294
- var G = Object.defineProperty;
24295
- var $ = Object.getOwnPropertyDescriptor;
24296
- var Q = Object.getOwnPropertyNames;
24297
- var X = Object.getPrototypeOf;
24298
- var tt = Object.prototype.hasOwnProperty;
24299
- var et = (c, p) => () => (p || c((p = { exports: {} }).exports, p), p.exports);
24300
- var it = (c, p, y, m) => {
24293
+ var X = Object.create;
24294
+ var z = Object.defineProperty;
24295
+ var tt = Object.getOwnPropertyDescriptor;
24296
+ var et = Object.getOwnPropertyNames;
24297
+ var it = Object.getPrototypeOf;
24298
+ var nt = Object.prototype.hasOwnProperty;
24299
+ var ot = (c, p) => () => (p || c((p = { exports: {} }).exports, p), p.exports);
24300
+ var rt = (c, p, y, m) => {
24301
24301
  if (p && typeof p == "object" || typeof p == "function")
24302
- for (let C of Q(p))
24303
- !tt.call(c, C) && C !== y && G(c, C, { get: () => p[C], enumerable: !(m = $(p, C)) || m.enumerable });
24302
+ for (let C of et(p))
24303
+ !nt.call(c, C) && C !== y && z(c, C, { get: () => p[C], enumerable: !(m = tt(p, C)) || m.enumerable });
24304
24304
  return c;
24305
24305
  };
24306
- var nt = (c, p, y) => (y = c != null ? Z(X(c)) : {}, it(p || !c || !c.__esModule ? G(y, "default", { value: c, enumerable: true }) : y, c));
24307
- var R = et((at, T) => {
24306
+ var st = (c, p, y) => (y = c != null ? X(it(c)) : {}, rt(p || !c || !c.__esModule ? z(y, "default", { value: c, enumerable: true }) : y, c));
24307
+ var V = ot((dt, F) => {
24308
24308
  (function(c) {
24309
- typeof T == "object" && T.exports ? T.exports = c() : window.intlTelInput = c();
24309
+ typeof F == "object" && F.exports ? F.exports = c() : window.intlTelInput = c();
24310
24310
  })(function(c) {
24311
24311
  "use strict";
24312
24312
  return function() {
@@ -24320,39 +24320,39 @@ var R = et((at, T) => {
24320
24320
  typeof Object.getOwnPropertySymbols == "function" && e.push.apply(e, Object.getOwnPropertySymbols(t).filter(function(i) {
24321
24321
  return Object.getOwnPropertyDescriptor(t, i).enumerable;
24322
24322
  })), e.forEach(function(i) {
24323
- N(s, i, t[i]);
24323
+ P(s, i, t[i]);
24324
24324
  });
24325
24325
  }
24326
24326
  return s;
24327
24327
  }
24328
- function N(s, n, t) {
24329
- return n = D(n), n in s ? Object.defineProperty(s, n, { value: t, enumerable: true, configurable: true, writable: true }) : s[n] = t, s;
24328
+ function P(s, n, t) {
24329
+ return n = T(n), n in s ? Object.defineProperty(s, n, { value: t, enumerable: true, configurable: true, writable: true }) : s[n] = t, s;
24330
24330
  }
24331
- function F(s, n) {
24332
- return _(s) || w(s, n) || x(s, n) || P();
24331
+ function x(s, n) {
24332
+ return _(s) || L(s, n) || U(s, n) || O();
24333
24333
  }
24334
- function P() {
24334
+ function O() {
24335
24335
  throw new TypeError(`Invalid attempt to destructure non-iterable instance.
24336
24336
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
24337
24337
  }
24338
- function x(s, n) {
24338
+ function U(s, n) {
24339
24339
  if (s) {
24340
24340
  if (typeof s == "string")
24341
- return k(s, n);
24341
+ return E(s, n);
24342
24342
  var t = Object.prototype.toString.call(s).slice(8, -1);
24343
24343
  if (t === "Object" && s.constructor && (t = s.constructor.name), t === "Map" || t === "Set")
24344
24344
  return Array.from(s);
24345
24345
  if (t === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))
24346
- return k(s, n);
24346
+ return E(s, n);
24347
24347
  }
24348
24348
  }
24349
- function k(s, n) {
24349
+ function E(s, n) {
24350
24350
  (n == null || n > s.length) && (n = s.length);
24351
24351
  for (var t = 0, e = new Array(n); t < n; t++)
24352
24352
  e[t] = s[t];
24353
24353
  return e;
24354
24354
  }
24355
- function w(s, n) {
24355
+ function L(s, n) {
24356
24356
  var t = s == null ? null : typeof Symbol < "u" && s[Symbol.iterator] || s["@@iterator"];
24357
24357
  if (t != null) {
24358
24358
  var e, i, o, r, a = [], l = true, u = false;
@@ -24382,24 +24382,24 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24382
24382
  if (Array.isArray(s))
24383
24383
  return s;
24384
24384
  }
24385
- function I(s, n) {
24385
+ function S(s, n) {
24386
24386
  if (!(s instanceof n))
24387
24387
  throw new TypeError("Cannot call a class as a function");
24388
24388
  }
24389
24389
  function b(s, n) {
24390
24390
  for (var t = 0; t < n.length; t++) {
24391
24391
  var e = n[t];
24392
- e.enumerable = e.enumerable || false, e.configurable = true, "value" in e && (e.writable = true), Object.defineProperty(s, D(e.key), e);
24392
+ e.enumerable = e.enumerable || false, e.configurable = true, "value" in e && (e.writable = true), Object.defineProperty(s, T(e.key), e);
24393
24393
  }
24394
24394
  }
24395
- function O(s, n, t) {
24395
+ function M(s, n, t) {
24396
24396
  return n && b(s.prototype, n), t && b(s, t), Object.defineProperty(s, "prototype", { writable: false }), s;
24397
24397
  }
24398
- function D(s) {
24399
- var n = V(s, "string");
24398
+ function T(s) {
24399
+ var n = q(s, "string");
24400
24400
  return typeof n == "symbol" ? n : String(n);
24401
24401
  }
24402
- function V(s, n) {
24402
+ function q(s, n) {
24403
24403
  if (typeof s != "object" || s === null)
24404
24404
  return s;
24405
24405
  var t = s[Symbol.toPrimitive];
@@ -24411,24 +24411,24 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24411
24411
  }
24412
24412
  return (n === "string" ? String : Number)(s);
24413
24413
  }
24414
- var L = { getInstance: function(n) {
24414
+ var k = { getInstance: function(n) {
24415
24415
  var t = n.getAttribute("data-intl-tel-input-id");
24416
24416
  return window.intlTelInputGlobals.instances[t];
24417
24417
  }, instances: {}, documentReady: function() {
24418
24418
  return document.readyState === "complete";
24419
24419
  } };
24420
- typeof window == "object" && (window.intlTelInputGlobals = L);
24421
- var H = 0, M = { allowDropdown: true, autoInsertDialCode: false, autoPlaceholder: "polite", countrySearch: true, containerClass: "", customPlaceholder: null, dropdownContainer: null, excludeCountries: [], fixDropdownWidth: true, formatAsYouType: true, formatOnDisplay: true, geoIpLookup: null, hiddenInput: null, i18n: {}, initialCountry: "", nationalMode: true, onlyCountries: [], placeholderNumberType: "MOBILE", preferredCountries: [], showFlags: true, showSelectedDialCode: false, useFullscreenPopup: typeof navigator < "u" && typeof window < "u" ? /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 500 : false, utilsScript: "" }, W = ["800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889"], S = function(n) {
24420
+ typeof window == "object" && (window.intlTelInputGlobals = k);
24421
+ var Y = 0, R = { allowDropdown: true, autoInsertDialCode: false, autoPlaceholder: "polite", countrySearch: true, containerClass: "", customPlaceholder: null, defaultToFirstCountry: true, dropdownContainer: null, excludeCountries: [], fixDropdownWidth: true, formatAsYouType: true, formatOnDisplay: true, geoIpLookup: null, hiddenInput: null, i18n: {}, initialCountry: "", nationalMode: true, onlyCountries: [], placeholderNumberType: "MOBILE", preferredCountries: [], showFlags: true, showSelectedDialCode: false, useFullscreenPopup: typeof navigator < "u" && typeof window < "u" ? /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 500 : false, utilsScript: "" }, J = ["800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889"], D = function(n) {
24422
24422
  var t = window.intlTelInputGlobals.instances;
24423
24423
  Object.values(t).forEach(function(e) {
24424
24424
  return e[n]();
24425
24425
  });
24426
- }, q = function() {
24426
+ }, Z = function() {
24427
24427
  function s(n) {
24428
24428
  var t = arguments.length > 1 && arguments[1] !== c ? arguments[1] : {};
24429
- I(this, s), this.id = H++, this.telInput = n, this.activeItem = null, this.highlightedItem = null, this.options = Object.assign({}, M, t), this.hadInitialPlaceholder = !!n.getAttribute("placeholder");
24429
+ S(this, s), this.id = Y++, this.telInput = n, this.activeItem = null, this.highlightedItem = null, this.options = Object.assign({}, R, t), this.hadInitialPlaceholder = !!n.getAttribute("placeholder");
24430
24430
  }
24431
- return O(s, [{ key: "_init", value: function() {
24431
+ return M(s, [{ key: "_init", value: function() {
24432
24432
  var t = this;
24433
24433
  this.options.useFullscreenPopup && (this.options.fixDropdownWidth = false), this.options.countrySearch && !this.options.useFullscreenPopup && (this.options.fixDropdownWidth = true), this.options.nationalMode && (this.options.autoInsertDialCode = false), this.options.showSelectedDialCode && (this.options.autoInsertDialCode = false);
24434
24434
  var e = this.options.allowDropdown && !this.options.showSelectedDialCode;
@@ -24503,7 +24503,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24503
24503
  } }, { key: "_createEl", value: function(t, e, i) {
24504
24504
  var o = document.createElement(t);
24505
24505
  return e && Object.entries(e).forEach(function(r) {
24506
- var a = F(r, 2), l = a[0], u = a[1];
24506
+ var a = x(r, 2), l = a[0], u = a[1];
24507
24507
  return o.setAttribute(l, u);
24508
24508
  }), i && i.appendChild(o), o;
24509
24509
  } }, { key: "_generateMarkup", value: function() {
@@ -24512,19 +24512,21 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24512
24512
  e && (f += " iti--allow-dropdown"), i && (f += " iti--show-selected-dial-code"), o && (f += " iti--show-flags"), r && (f += " ".concat(r)), h || (f += " iti--inline-dropdown");
24513
24513
  var v = this._createEl("div", { class: f });
24514
24514
  this.telInput.parentNode.insertBefore(v, this.telInput);
24515
- var A = e || o || i;
24516
- if (A && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, v)), v.appendChild(this.telInput), A && (this.selectedFlag = this._createEl("div", C({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24515
+ var w = e || o || i;
24516
+ if (w && (this.flagsContainer = this._createEl("div", { class: "iti__flag-container" }, v)), v.appendChild(this.telInput), w && (this.selectedFlag = this._createEl("div", C({ class: "iti__selected-flag" }, e && { role: "combobox", "aria-haspopup": "listbox", "aria-controls": "iti-".concat(this.id, "__country-listbox"), "aria-expanded": "false", "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country" }), this.flagsContainer)), o && (this.selectedFlagInner = this._createEl("div", { class: "iti__flag" }, this.selectedFlag)), this.selectedFlag && this.telInput.disabled && this.selectedFlag.setAttribute("aria-disabled", "true"), i && (this.selectedDialCode = this._createEl("div", { class: "iti__selected-dial-code" }, this.selectedFlag)), e) {
24517
24517
  this.telInput.disabled || this.selectedFlag.setAttribute("tabindex", "0"), this.dropdownArrow = this._createEl("div", { class: "iti__arrow" }, this.selectedFlag);
24518
- var Y = u ? "" : "iti--flexible-dropdown-width";
24519
- if (this.dropdownContent = this._createEl("div", { class: "iti__dropdown-content iti__hide ".concat(Y) }), g && (this.searchInput = this._createEl("input", { type: "text", class: "iti__search-input", placeholder: this.options.i18n.searchPlaceholder || "Search" }, this.dropdownContent)), this.countryList = this._createEl("ul", { class: "iti__country-list", id: "iti-".concat(this.id, "__country-listbox"), role: "listbox", "aria-label": this.options.i18n.countryListAriaLabel || "List of countries" }, this.dropdownContent), this.preferredCountries.length && !g && (this._appendListItems(this.preferredCountries, "iti__preferred", true), this._createEl("li", { class: "iti__divider", "aria-hidden": "true" }, this.countryList)), this._appendListItems(this.countries, "iti__standard"), l) {
24520
- var E = "iti iti--container";
24521
- h ? E += " iti--fullscreen-popup" : E += " iti--inline-dropdown", g && (E += " iti--country-search"), this.dropdown = this._createEl("div", { class: E }), this.dropdown.appendChild(this.dropdownContent);
24518
+ var $ = u ? "" : "iti--flexible-dropdown-width";
24519
+ if (this.dropdownContent = this._createEl("div", { class: "iti__dropdown-content iti__hide ".concat($) }), g && (this.searchInput = this._createEl("input", { type: "text", class: "iti__search-input", placeholder: this.options.i18n.searchPlaceholder || "Search" }, this.dropdownContent)), this.countryList = this._createEl("ul", { class: "iti__country-list", id: "iti-".concat(this.id, "__country-listbox"), role: "listbox", "aria-label": this.options.i18n.countryListAriaLabel || "List of countries" }, this.dropdownContent), this.preferredCountries.length && !g && (this._appendListItems(this.preferredCountries, "iti__preferred", true), this._createEl("li", { class: "iti__divider", "aria-hidden": "true" }, this.countryList)), this._appendListItems(this.countries, "iti__standard"), l) {
24520
+ var N = "iti iti--container";
24521
+ h ? N += " iti--fullscreen-popup" : N += " iti--inline-dropdown", g && (N += " iti--country-search"), this.dropdown = this._createEl("div", { class: N }), this.dropdown.appendChild(this.dropdownContent);
24522
24522
  } else
24523
24523
  this.flagsContainer.appendChild(this.dropdownContent);
24524
24524
  }
24525
24525
  if (a) {
24526
- var J = this.telInput.getAttribute("name"), j = a(J);
24527
- this.hiddenInput = this._createEl("input", { type: "hidden", name: j }), v.appendChild(this.hiddenInput), this.hiddenInputCountry = this._createEl("input", { type: "hidden", name: "".concat(j, "_country") }), v.appendChild(this.hiddenInputCountry);
24526
+ var B = this.telInput.getAttribute("name"), A = a(B), Q = A !== null && typeof A == "object", I, j;
24527
+ if (Q ? (I = A.phone || B, j = A.country || "".concat(I, "_country")) : (I = A || B, j = "".concat(I, "_country")), !I)
24528
+ return;
24529
+ this.hiddenInput = this._createEl("input", { type: "hidden", name: I }), this.hiddenInputCountry = this._createEl("input", { type: "hidden", name: j }), v.appendChild(this.hiddenInput), v.appendChild(this.hiddenInputCountry);
24528
24530
  }
24529
24531
  } }, { key: "_appendListItems", value: function(t, e, i) {
24530
24532
  for (var o = 0; o < t.length; o++) {
@@ -24534,12 +24536,12 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24534
24536
  this.options.showFlags && (u += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(r.iso2, "'></div></div>")), u += "<span class='iti__country-name'>".concat(r.name, "</span>"), u += "<span class='iti__dial-code'>+".concat(r.dialCode, "</span>"), l.insertAdjacentHTML("beforeend", u);
24535
24537
  }
24536
24538
  } }, { key: "_setInitialState", value: function() {
24537
- var t = arguments.length > 0 && arguments[0] !== c ? arguments[0] : false, e = this.telInput.getAttribute("value"), i = this.telInput.value, o = e && e.charAt(0) === "+" && (!i || i.charAt(0) !== "+"), r = o ? e : i, a = this._getDialCode(r), l = this._isRegionlessNanp(r), u = this.options, h = u.initialCountry, g = u.autoInsertDialCode;
24539
+ var t = arguments.length > 0 && arguments[0] !== c ? arguments[0] : false, e = this.telInput.getAttribute("value"), i = this.telInput.value, o = e && e.charAt(0) === "+" && (!i || i.charAt(0) !== "+"), r = o ? e : i, a = this._getDialCode(r), l = this._isRegionlessNanp(r), u = this.options, h = u.initialCountry, g = u.autoInsertDialCode, f = u.defaultToFirstCountry;
24538
24540
  if (a && !l)
24539
24541
  this._updateFlagFromNumber(r);
24540
24542
  else if (h !== "auto" || t) {
24541
- var f = h ? h.toLowerCase() : "", v = f && this._getCountryData(f, true);
24542
- v ? this._setFlag(f) : a && l ? this._setFlag("us") : (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, r || this._setFlag(this.defaultCountry)), !r && g && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24543
+ var v = h ? h.toLowerCase() : "", w = v && this._getCountryData(v, true);
24544
+ w ? this._setFlag(v) : a && l ? this._setFlag("us") : f && (this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2, r || this._setFlag(this.defaultCountry)), !r && g && (this.telInput.value = "+".concat(this.selectedCountryData.dialCode));
24543
24545
  }
24544
24546
  r && this._updateValFromNumber(r);
24545
24547
  } }, { key: "_initListeners", value: function() {
@@ -24571,10 +24573,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24571
24573
  window.intlTelInputGlobals.autoCountry ? this.handleAutoCountry() : window.intlTelInputGlobals.startedLoadingAutoCountry || (window.intlTelInputGlobals.startedLoadingAutoCountry = true, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(function() {
24572
24574
  var e = arguments.length > 0 && arguments[0] !== c ? arguments[0] : "", i = e.toLowerCase(), o = i && t._getCountryData(i, true);
24573
24575
  o ? (window.intlTelInputGlobals.autoCountry = i, setTimeout(function() {
24574
- return S("handleAutoCountry");
24575
- })) : (t._setInitialState(true), S("rejectAutoCountryPromise"));
24576
+ return D("handleAutoCountry");
24577
+ })) : (t._setInitialState(true), D("rejectAutoCountryPromise"));
24576
24578
  }, function() {
24577
- return S("rejectAutoCountryPromise");
24579
+ return D("rejectAutoCountryPromise");
24578
24580
  }));
24579
24581
  } }, { key: "_initKeyListeners", value: function() {
24580
24582
  var t = this, e = false;
@@ -24719,7 +24721,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24719
24721
  var e = this._getNumeric(t);
24720
24722
  if (e.charAt(0) === "1") {
24721
24723
  var i = e.substr(1, 3);
24722
- return W.indexOf(i) !== -1;
24724
+ return J.indexOf(i) !== -1;
24723
24725
  }
24724
24726
  return false;
24725
24727
  } }, { key: "_highlightListItem", value: function(t, e) {
@@ -24779,8 +24781,8 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24779
24781
  e && (f -= v), i.scrollTop = f;
24780
24782
  else if (g > l) {
24781
24783
  e && (f += v);
24782
- var A = r - u;
24783
- i.scrollTop = f - A;
24784
+ var w = r - u;
24785
+ i.scrollTop = f - w;
24784
24786
  }
24785
24787
  } }, { key: "_updateDialCode", value: function(t) {
24786
24788
  var e = this.telInput.value, i = "+".concat(t), o;
@@ -24877,60 +24879,60 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
24877
24879
  this.options.placeholderNumberType = t, this._updatePlaceholder();
24878
24880
  } }]), s;
24879
24881
  }();
24880
- L.getCountryData = function() {
24882
+ k.getCountryData = function() {
24881
24883
  return p;
24882
24884
  };
24883
- var B = function(n, t, e) {
24885
+ var K = function(n, t, e) {
24884
24886
  var i = document.createElement("script");
24885
24887
  i.onload = function() {
24886
- S("handleUtils"), t && t();
24888
+ D("handleUtils"), t && t();
24887
24889
  }, i.onerror = function() {
24888
- S("rejectUtilsScriptPromise"), e && e();
24890
+ D("rejectUtilsScriptPromise"), e && e();
24889
24891
  }, i.className = "iti-load-utils", i.async = true, i.src = n, document.body.appendChild(i);
24890
24892
  };
24891
- return L.loadUtils = function(s) {
24893
+ return k.loadUtils = function(s) {
24892
24894
  if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
24893
24895
  if (window.intlTelInputGlobals.startedLoadingUtilsScript = true, typeof Promise < "u")
24894
24896
  return new Promise(function(n, t) {
24895
- return B(s, n, t);
24897
+ return K(s, n, t);
24896
24898
  });
24897
- B(s);
24899
+ K(s);
24898
24900
  }
24899
24901
  return null;
24900
- }, L.defaults = M, L.version = "19.2.20", function(s, n) {
24901
- var t = new q(s, n);
24902
+ }, k.defaults = R, k.version = "19.4.0", function(s, n) {
24903
+ var t = new Z(s, n);
24902
24904
  return t._init(), s.setAttribute("data-intl-tel-input-id", t.id), window.intlTelInputGlobals.instances[t.id] = t, t;
24903
24905
  };
24904
24906
  }();
24905
24907
  });
24906
24908
  });
24907
- var z = nt(R());
24908
- var U = ({ initialValue: c, onChangeNumber: p, onChangeCountry: y, onChangeValidity: m, onChangeErrorCode: C, initOptions: N, className: F, disabled: P, onFocus: x, onBlur: k }) => {
24909
- let w = (0, import_react.useRef)(null), _ = (0, import_react.useRef)(null), I = () => {
24910
- let b = _.current.getNumber(), O = _.current.getSelectedCountryData().iso2;
24911
- if (p(b), y(O), _.current.isValidNumber())
24909
+ var W = st(V());
24910
+ var G = ({ initialValue: c, onChangeNumber: p, onChangeCountry: y, onChangeValidity: m, onChangeErrorCode: C, initOptions: P, className: x, disabled: O, onFocus: U, onBlur: E }) => {
24911
+ let L = (0, import_react.useRef)(null), _ = (0, import_react.useRef)(null), S = () => {
24912
+ let b = _.current.getNumber(), M = _.current.getSelectedCountryData().iso2;
24913
+ if (p(b), y(M), _.current.isValidNumber())
24912
24914
  m(true), C(null);
24913
24915
  else {
24914
- let D = _.current.getValidationError();
24915
- m(false), C(D);
24916
+ let T = _.current.getValidationError();
24917
+ m(false), C(T);
24916
24918
  }
24917
24919
  };
24918
24920
  return (0, import_react.useEffect)(() => {
24919
- let b = w.current;
24920
- return _.current = (0, z.default)(w.current, N), b.addEventListener("countrychange", I), () => {
24921
- b.removeEventListener("countrychange", I), _.current.destroy();
24921
+ let b = L.current;
24922
+ return _.current = (0, W.default)(L.current, P), b.addEventListener("countrychange", S), () => {
24923
+ b.removeEventListener("countrychange", S), _.current.destroy();
24922
24924
  };
24923
- }, []), import_react.default.createElement("input", { type: "tel", ref: w, onInput: I, defaultValue: c, className: F, disabled: P, onFocus: x, onBlur: k });
24925
+ }, []), import_react.default.createElement("input", { type: "tel", ref: L, onInput: S, defaultValue: c, className: x, disabled: O, onFocus: U, onBlur: E });
24924
24926
  };
24925
- U.propTypes = { initialValue: import_prop_types.default.string, onChangeNumber: import_prop_types.default.func, onChangeCountry: import_prop_types.default.func, onChangeValidity: import_prop_types.default.func, onChangeErrorCode: import_prop_types.default.func, initOptions: import_prop_types.default.shape({ allowDropdown: import_prop_types.default.bool, autoInsertDialCode: import_prop_types.default.bool, autoPlaceholder: import_prop_types.default.string, containerClass: import_prop_types.default.string, countrySearch: import_prop_types.default.bool, customPlaceholder: import_prop_types.default.func, dropdownContainer: import_prop_types.default.node, excludeCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), fixDropdownWidth: import_prop_types.default.bool, formatAsYouType: import_prop_types.default.bool, formatOnDisplay: import_prop_types.default.bool, geoIpLookup: import_prop_types.default.func, hiddenInput: import_prop_types.default.func, i18n: import_prop_types.default.objectOf(import_prop_types.default.string), initialCountry: import_prop_types.default.string, nationalMode: import_prop_types.default.bool, onlyCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), placeholderNumberType: import_prop_types.default.string, preferredCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), showFlags: import_prop_types.default.bool, showSelectedDialCode: import_prop_types.default.bool, useFullscreenPopup: import_prop_types.default.bool, utilsScript: import_prop_types.default.string }), className: import_prop_types.default.string, disabled: import_prop_types.default.bool, onFocus: import_prop_types.default.func, onBlur: import_prop_types.default.func };
24926
- U.defaultProps = { initialValue: "", onChangeNumber: () => {
24927
+ G.propTypes = { initialValue: import_prop_types.default.string, onChangeNumber: import_prop_types.default.func, onChangeCountry: import_prop_types.default.func, onChangeValidity: import_prop_types.default.func, onChangeErrorCode: import_prop_types.default.func, initOptions: import_prop_types.default.shape({ allowDropdown: import_prop_types.default.bool, autoInsertDialCode: import_prop_types.default.bool, autoPlaceholder: import_prop_types.default.string, containerClass: import_prop_types.default.string, countrySearch: import_prop_types.default.bool, customPlaceholder: import_prop_types.default.func, dropdownContainer: import_prop_types.default.node, excludeCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), fixDropdownWidth: import_prop_types.default.bool, formatAsYouType: import_prop_types.default.bool, formatOnDisplay: import_prop_types.default.bool, geoIpLookup: import_prop_types.default.func, hiddenInput: import_prop_types.default.func, i18n: import_prop_types.default.objectOf(import_prop_types.default.string), initialCountry: import_prop_types.default.string, nationalMode: import_prop_types.default.bool, onlyCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), placeholderNumberType: import_prop_types.default.string, preferredCountries: import_prop_types.default.arrayOf(import_prop_types.default.string), showFlags: import_prop_types.default.bool, showSelectedDialCode: import_prop_types.default.bool, useFullscreenPopup: import_prop_types.default.bool, utilsScript: import_prop_types.default.string }), className: import_prop_types.default.string, disabled: import_prop_types.default.bool, onFocus: import_prop_types.default.func, onBlur: import_prop_types.default.func };
24928
+ G.defaultProps = { initialValue: "", onChangeNumber: () => {
24927
24929
  }, onChangeCountry: () => {
24928
24930
  }, onChangeValidity: () => {
24929
24931
  }, onChangeErrorCode: () => {
24930
24932
  }, initOptions: {}, className: "", disabled: false, onFocus: () => {
24931
24933
  }, onBlur: () => {
24932
24934
  } };
24933
- var dt = U;
24935
+ var pt = G;
24934
24936
 
24935
24937
  // react/demo/ValidationApp.js
24936
24938
  var errorMap = [
@@ -24954,7 +24956,7 @@ var App = () => {
24954
24956
  }
24955
24957
  };
24956
24958
  return /* @__PURE__ */ import_react2.default.createElement("form", null, /* @__PURE__ */ import_react2.default.createElement(
24957
- dt,
24959
+ pt,
24958
24960
  {
24959
24961
  onChangeNumber: setNumber,
24960
24962
  onChangeValidity: setIsValid,
package/spec.html CHANGED
@@ -90,6 +90,8 @@
90
90
 
91
91
  <script src="src/spec/tests/options/geoIpLookup.js"></script>
92
92
 
93
+ <script src="src/spec/tests/options/hiddenInput.js"></script>
94
+
93
95
  <script src="src/spec/tests/options/initialCountry.js"></script>
94
96
 
95
97
  <script src="src/spec/tests/options/nationalMode.js"></script>
@@ -18,7 +18,6 @@ const defaults = {
18
18
  // whether or not to allow the dropdown
19
19
  allowDropdown: true,
20
20
  // auto insert dial code (A) on init, (B) on user selecting a country, (C) on calling setCountry
21
- // also listen for blur/submit and auto remove dial code if that's all there is
22
21
  autoInsertDialCode: false,
23
22
  // add a placeholder in the input with an example number for the selected country
24
23
  autoPlaceholder: "polite",
@@ -28,6 +27,8 @@ const defaults = {
28
27
  containerClass: "",
29
28
  // modify the auto placeholder
30
29
  customPlaceholder: null,
30
+ // by default, initialise with the first country in the list selected (if no country set via the initial value or initialCountry option)
31
+ defaultToFirstCountry: true,
31
32
  // append menu to specified element
32
33
  dropdownContainer: null,
33
34
  // don't display these countries
@@ -514,17 +515,38 @@ class Iti {
514
515
 
515
516
  if (hiddenInput) {
516
517
  const telInputName = this.telInput.getAttribute("name");
517
- const hiddenInputName = hiddenInput(telInputName);
518
+ const result = hiddenInput(telInputName);
519
+ const isObject = result !== null && typeof result === "object";
520
+
521
+ let hiddenInputPhoneName;
522
+ let hiddenInputCountryName;
523
+
524
+ if (isObject) {
525
+ hiddenInputPhoneName = result.phone || telInputName;
526
+ hiddenInputCountryName = result.country || `${hiddenInputPhoneName}_country`;
527
+ } else {
528
+ hiddenInputPhoneName = result || telInputName;
529
+ hiddenInputCountryName = `${hiddenInputPhoneName}_country`;
530
+ }
531
+
532
+ // Check if a name has been determined for the phone input field after all conditions
533
+ if (!hiddenInputPhoneName) {
534
+ return;
535
+ }
536
+
537
+ // Create hidden input for the full international number
518
538
  this.hiddenInput = this._createEl("input", {
519
539
  type: "hidden",
520
- name: hiddenInputName
540
+ name: hiddenInputPhoneName
521
541
  });
522
- wrapper.appendChild(this.hiddenInput);
523
- // add a 2nd hidden input for the selected country code - this is useful for handling invalid numbers with server-side validation, as getNumber does not always include the international dial code for invalid numbers
542
+
543
+ // Create hidden input for the selected country code
524
544
  this.hiddenInputCountry = this._createEl("input", {
525
545
  type: "hidden",
526
- name: `${hiddenInputName}_country`
546
+ name: hiddenInputCountryName
527
547
  });
548
+
549
+ wrapper.appendChild(this.hiddenInput);
528
550
  wrapper.appendChild(this.hiddenInputCountry);
529
551
  }
530
552
  }
@@ -582,7 +604,7 @@ class Iti {
582
604
  const val = useAttribute ? attributeValue : inputValue;
583
605
  const dialCode = this._getDialCode(val);
584
606
  const isRegionlessNanp = this._isRegionlessNanp(val);
585
- const { initialCountry, autoInsertDialCode } = this.options;
607
+ const { initialCountry, autoInsertDialCode, defaultToFirstCountry } = this.options;
586
608
 
587
609
  // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
588
610
  // flag, else fall back to the default country
@@ -598,7 +620,7 @@ class Iti {
598
620
  if (dialCode && isRegionlessNanp) {
599
621
  // has intl dial code, is regionless nanp, and no initialCountry, so default to US
600
622
  this._setFlag("us");
601
- } else {
623
+ } else if (defaultToFirstCountry) {
602
624
  // no dial code and no initialCountry, so default to first in list
603
625
  this.defaultCountry = this.preferredCountries.length
604
626
  ? this.preferredCountries[0].iso2
@@ -50,6 +50,11 @@ var getParentElement = function(i) {
50
50
  return i.parent();
51
51
  };
52
52
 
53
+ var getHiddenInputs = function(i) {
54
+ i = i || input;
55
+ return i.parent().find("input[type=hidden]");
56
+ };
57
+
53
58
  var getDropdownContent = function(i) {
54
59
  i = i || input;
55
60
  return i.parent().find(".iti__dropdown-content");
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ describe("hiddenInput: ", function() {
4
+
5
+ beforeEach(function() {
6
+ intlSetup();
7
+ });
8
+
9
+ afterEach(function() {
10
+ intlTeardown();
11
+ });
12
+
13
+ describe("init plugin with hiddenInput returning a string", function() {
14
+
15
+ beforeEach(function() {
16
+ input = $("<input>").wrap("div");
17
+ iti = window.intlTelInput(input[0], {
18
+ hiddenInput: () => "phone_full"
19
+ });
20
+ });
21
+
22
+ it("creates two hidden inputs", function() {
23
+ expect(getHiddenInputs()).toHaveLength(2);
24
+ });
25
+
26
+ it("sets the name of the first hidden input to the returned string", function() {
27
+ expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone_full");
28
+ });
29
+
30
+ it("sets the name of the second hidden input to the returned string with a '_country' suffix", function() {
31
+ expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_full_country");
32
+ });
33
+ });
34
+
35
+ describe("init plugin with hiddenInput returning an object with correct properties", function() {
36
+
37
+ beforeEach(function() {
38
+ input = $("<input>").wrap("div");
39
+ iti = window.intlTelInput(input[0], {
40
+ hiddenInput: () => ({
41
+ phone: "phone_full",
42
+ country: "phone_country"
43
+ })
44
+ });
45
+ });
46
+
47
+ it("creates two hidden inputs", function() {
48
+ expect(getHiddenInputs()).toHaveLength(2);
49
+ });
50
+
51
+ it("sets the name of the first hidden input to the returned object's 'phone' property", function() {
52
+ expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone_full");
53
+ });
54
+
55
+ it("sets the name of the second hidden input to the returned object's 'country' property", function() {
56
+ expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
57
+ });
58
+ });
59
+
60
+ describe("init plugin with hiddenInput returning an object with incorrect properties", function() {
61
+
62
+ beforeEach(function() {
63
+ input = $("<input name='phone'>").wrap("div");
64
+ iti = window.intlTelInput(input[0], {
65
+ hiddenInput: () => ({
66
+ test: "test",
67
+ data: "data"
68
+ })
69
+ });
70
+ });
71
+
72
+ it("creates two hidden inputs", function() {
73
+ expect(getHiddenInputs()).toHaveLength(2);
74
+ });
75
+
76
+ it("sets the name of the hidden input to the name of the input", function() {
77
+ expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone");
78
+ });
79
+
80
+ it("sets the name of the second hidden input to the name of the input with a '_country' suffix", function() {
81
+ expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
82
+ });
83
+ });
84
+
85
+ describe("init plugin with hiddenInput returning an empty object", function() {
86
+
87
+ beforeEach(function() {
88
+ input = $("<input name='phone'>").wrap("div");
89
+ iti = window.intlTelInput(input[0], {
90
+ hiddenInput: () => ({})
91
+ });
92
+ });
93
+
94
+ it("creates two hidden inputs", function() {
95
+ expect(getHiddenInputs()).toHaveLength(2);
96
+ });
97
+
98
+ it("sets the name of the hidden input to the name of the input", function() {
99
+ expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone");
100
+ });
101
+
102
+ it("sets the name of the second hidden input to the name of the input with a '_country' suffix", function() {
103
+ expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
104
+ });
105
+ });
106
+
107
+ describe("init plugin with no name attribute set on input and hiddenInput returning an empty object", function() {
108
+
109
+ beforeEach(function() {
110
+ input = $("<input>").wrap("div");
111
+ iti = window.intlTelInput(input[0], {
112
+ hiddenInput: () => ({})
113
+ });
114
+ });
115
+
116
+ it("does not create any hidden inputs", function() {
117
+ expect(getHiddenInputs()).toHaveLength(0);
118
+ });
119
+ });
120
+ });