intl-tel-input 19.5.2 → 19.5.3
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.
- package/README.md +12 -6
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput-jquery.js +75 -65
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +75 -65
- package/build/js/intlTelInput.min.js +3 -3
- package/composer.json +1 -1
- package/demo.html +1 -1
- package/grunt/replace.js +3 -3
- package/package.json +1 -1
- package/react/build/IntlTelInput.cjs.js +2 -2
- package/react/build/IntlTelInput.cjs.js.map +3 -3
- package/react/build/IntlTelInput.esm.js +2 -2
- package/react/build/IntlTelInput.esm.js.map +3 -3
- package/react/demo/simple-bundle.js +139 -139
- package/react/demo/validation-bundle.js +139 -139
- package/react/src/IntlTelInput.js +4 -0
- package/screenshots/empty-country.png +0 -0
- package/src/js/intlTelInput.js +77 -66
- package/src/spec/helpers/helpers.js +2 -2
- package/src/spec/tests/core/multipleInstances.js +14 -14
- package/src/spec/tests/core/usingDropdown.js +4 -4
- package/src/spec/tests/methods/getValidationError.js +1 -1
- package/src/spec/tests/methods/setCountry.js +5 -20
- package/src/spec/tests/options/onlyCountries.js +3 -3
package/src/js/intlTelInput.js
CHANGED
|
@@ -200,8 +200,8 @@ class Iti {
|
|
|
200
200
|
// process onlyCountries or excludeCountries array if present
|
|
201
201
|
this._processAllCountries();
|
|
202
202
|
|
|
203
|
-
//
|
|
204
|
-
this.
|
|
203
|
+
// generate this.dialCodes and this.dialCodeToIso2Map
|
|
204
|
+
this._processDialCodes();
|
|
205
205
|
|
|
206
206
|
// process the preferredCountries
|
|
207
207
|
this._processPreferredCountries();
|
|
@@ -215,24 +215,24 @@ class Iti {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
// add a
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
this.
|
|
218
|
+
// add a dial code to this.dialCodeToIso2Map
|
|
219
|
+
_addToDialCodeMap(iso2, dialCode, priority) {
|
|
220
|
+
if (dialCode.length > this.dialCodeMaxLen) {
|
|
221
|
+
this.dialCodeMaxLen = dialCode.length;
|
|
222
222
|
}
|
|
223
|
-
if (!this.
|
|
224
|
-
this.
|
|
223
|
+
if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
|
|
224
|
+
this.dialCodeToIso2Map[dialCode] = [];
|
|
225
225
|
}
|
|
226
|
-
// bail if we already have this country for this
|
|
227
|
-
for (let i = 0; i < this.
|
|
228
|
-
if (this.
|
|
226
|
+
// bail if we already have this country for this dialCode
|
|
227
|
+
for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
|
|
228
|
+
if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
// check for undefined as 0 is falsy
|
|
233
233
|
const index =
|
|
234
|
-
priority !== undefined ? priority : this.
|
|
235
|
-
this.
|
|
234
|
+
priority !== undefined ? priority : this.dialCodeToIso2Map[dialCode].length;
|
|
235
|
+
this.dialCodeToIso2Map[dialCode][index] = iso2;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// process onlyCountries or excludeCountries array if present
|
|
@@ -277,13 +277,24 @@ class Iti {
|
|
|
277
277
|
return 0;
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
//
|
|
280
|
+
// generate this.dialCodes and this.dialCodeToIso2Map
|
|
281
|
+
_processDialCodes() {
|
|
282
|
+
// here we store just dial codes, where the key is the dial code, and the value is true
|
|
283
|
+
// e.g. { 1: true, 7: true, 20: true, ... }
|
|
284
284
|
this.dialCodes = {};
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
this.dialCodeMaxLen = 0;
|
|
286
|
+
|
|
287
|
+
// here we map dialCodes (inc both dialCode and dialCode+areaCode) to iso2 codes
|
|
288
|
+
/* e.g.
|
|
289
|
+
* {
|
|
290
|
+
* 1: [ 'us', 'ca', ... ], # all NANP countries
|
|
291
|
+
* 12: [ 'us', 'ca', ... ], # subset of NANP countries
|
|
292
|
+
* 120: [ 'us', 'ca' ], # just US and Canada
|
|
293
|
+
* 1204: [ 'ca' ], # only Canada
|
|
294
|
+
* ...
|
|
295
|
+
* }
|
|
296
|
+
*/
|
|
297
|
+
this.dialCodeToIso2Map = {};
|
|
287
298
|
|
|
288
299
|
// first: add dial codes
|
|
289
300
|
for (let i = 0; i < this.countries.length; i++) {
|
|
@@ -291,7 +302,7 @@ class Iti {
|
|
|
291
302
|
if (!this.dialCodes[c.dialCode]) {
|
|
292
303
|
this.dialCodes[c.dialCode] = true;
|
|
293
304
|
}
|
|
294
|
-
this.
|
|
305
|
+
this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
|
|
295
306
|
}
|
|
296
307
|
|
|
297
308
|
// next: add area codes
|
|
@@ -302,7 +313,7 @@ class Iti {
|
|
|
302
313
|
const c = this.countries[i];
|
|
303
314
|
// area codes
|
|
304
315
|
if (c.areaCodes) {
|
|
305
|
-
const
|
|
316
|
+
const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
|
|
306
317
|
// for each area code
|
|
307
318
|
for (let j = 0; j < c.areaCodes.length; j++) {
|
|
308
319
|
const areaCode = c.areaCodes[j];
|
|
@@ -310,11 +321,11 @@ class Iti {
|
|
|
310
321
|
for (let k = 1; k < areaCode.length; k++) {
|
|
311
322
|
const partialDialCode = c.dialCode + areaCode.substr(0, k);
|
|
312
323
|
// start with the root country, as that also matches this dial code
|
|
313
|
-
this.
|
|
314
|
-
this.
|
|
324
|
+
this._addToDialCodeMap(rootIso2Code, partialDialCode);
|
|
325
|
+
this._addToDialCodeMap(c.iso2, partialDialCode);
|
|
315
326
|
}
|
|
316
327
|
// add the full area code
|
|
317
|
-
this.
|
|
328
|
+
this._addToDialCodeMap(c.iso2, c.dialCode + areaCode);
|
|
318
329
|
}
|
|
319
330
|
}
|
|
320
331
|
}
|
|
@@ -325,8 +336,8 @@ class Iti {
|
|
|
325
336
|
_processPreferredCountries() {
|
|
326
337
|
this.preferredCountries = [];
|
|
327
338
|
for (let i = 0; i < this.options.preferredCountries.length; i++) {
|
|
328
|
-
const
|
|
329
|
-
const countryData = this._getCountryData(
|
|
339
|
+
const iso2 = this.options.preferredCountries[i].toLowerCase();
|
|
340
|
+
const countryData = this._getCountryData(iso2, true);
|
|
330
341
|
if (countryData) {
|
|
331
342
|
this.preferredCountries.push(countryData);
|
|
332
343
|
}
|
|
@@ -540,7 +551,7 @@ class Iti {
|
|
|
540
551
|
name: hiddenInputPhoneName
|
|
541
552
|
});
|
|
542
553
|
|
|
543
|
-
// Create hidden input for the selected country code
|
|
554
|
+
// Create hidden input for the selected country iso2 code
|
|
544
555
|
this.hiddenInputCountry = this._createEl("input", {
|
|
545
556
|
type: "hidden",
|
|
546
557
|
name: hiddenInputCountryName
|
|
@@ -771,11 +782,11 @@ class Iti {
|
|
|
771
782
|
|
|
772
783
|
if (typeof this.options.geoIpLookup === "function") {
|
|
773
784
|
this.options.geoIpLookup(
|
|
774
|
-
(
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
if (
|
|
778
|
-
window.intlTelInputGlobals.autoCountry =
|
|
785
|
+
(iso2 = "") => {
|
|
786
|
+
const iso2Lower = iso2.toLowerCase();
|
|
787
|
+
const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
|
|
788
|
+
if (isValidIso2) {
|
|
789
|
+
window.intlTelInputGlobals.autoCountry = iso2Lower;
|
|
779
790
|
// tell all instances the auto country is ready
|
|
780
791
|
// TODO: this should just be the current instances
|
|
781
792
|
// UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
|
|
@@ -1259,15 +1270,15 @@ class Iti {
|
|
|
1259
1270
|
// try and extract valid dial code from input
|
|
1260
1271
|
const dialCode = this._getDialCode(number, true);
|
|
1261
1272
|
const numeric = this._getNumeric(number);
|
|
1262
|
-
let
|
|
1273
|
+
let iso2 = null;
|
|
1263
1274
|
if (dialCode) {
|
|
1264
|
-
const
|
|
1275
|
+
const iso2Codes = this.dialCodeToIso2Map[this._getNumeric(dialCode)];
|
|
1265
1276
|
// check if the right country is already selected. this should be false if the number is
|
|
1266
1277
|
// longer than the matched dial code because in this case we need to make sure that if
|
|
1267
1278
|
// there are multiple country matches, that the first one is selected (note: we could
|
|
1268
1279
|
// just check that here, but it requires the same loop that we already have later)
|
|
1269
1280
|
const alreadySelected =
|
|
1270
|
-
|
|
1281
|
+
iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 &&
|
|
1271
1282
|
numeric.length <= dialCode.length - 1;
|
|
1272
1283
|
const isRegionlessNanpNumber =
|
|
1273
1284
|
selectedDialCode === "1" && this._isRegionlessNanp(numeric);
|
|
@@ -1277,11 +1288,11 @@ class Iti {
|
|
|
1277
1288
|
// AND
|
|
1278
1289
|
// B) the right country is not already selected
|
|
1279
1290
|
if (!isRegionlessNanpNumber && !alreadySelected) {
|
|
1280
|
-
// if using onlyCountries option,
|
|
1291
|
+
// if using onlyCountries option, iso2Codes[0] may be empty, so we must find the first
|
|
1281
1292
|
// non-empty index
|
|
1282
|
-
for (let j = 0; j <
|
|
1283
|
-
if (
|
|
1284
|
-
|
|
1293
|
+
for (let j = 0; j < iso2Codes.length; j++) {
|
|
1294
|
+
if (iso2Codes[j]) {
|
|
1295
|
+
iso2 = iso2Codes[j];
|
|
1285
1296
|
break;
|
|
1286
1297
|
}
|
|
1287
1298
|
}
|
|
@@ -1290,14 +1301,14 @@ class Iti {
|
|
|
1290
1301
|
// invalid dial code, so empty
|
|
1291
1302
|
// Note: use getNumeric here because the number has not been formatted yet, so could contain
|
|
1292
1303
|
// bad chars
|
|
1293
|
-
|
|
1304
|
+
iso2 = "";
|
|
1294
1305
|
} else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
|
|
1295
1306
|
// if no selected flag, and user either clears the input, or just types a plus, then show default
|
|
1296
|
-
|
|
1307
|
+
iso2 = this.defaultCountry;
|
|
1297
1308
|
}
|
|
1298
1309
|
|
|
1299
|
-
if (
|
|
1300
|
-
return this._setFlag(
|
|
1310
|
+
if (iso2 !== null) {
|
|
1311
|
+
return this._setFlag(iso2);
|
|
1301
1312
|
}
|
|
1302
1313
|
return false;
|
|
1303
1314
|
}
|
|
@@ -1331,32 +1342,32 @@ class Iti {
|
|
|
1331
1342
|
}
|
|
1332
1343
|
}
|
|
1333
1344
|
|
|
1334
|
-
// find the country data for the given
|
|
1345
|
+
// find the country data for the given iso2 code
|
|
1335
1346
|
// the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
|
|
1336
|
-
_getCountryData(
|
|
1347
|
+
_getCountryData(iso2, allowFail) {
|
|
1337
1348
|
for (let i = 0; i < this.countries.length; i++) {
|
|
1338
|
-
if (this.countries[i].iso2 ===
|
|
1349
|
+
if (this.countries[i].iso2 === iso2) {
|
|
1339
1350
|
return this.countries[i];
|
|
1340
1351
|
}
|
|
1341
1352
|
}
|
|
1342
1353
|
if (allowFail) {
|
|
1343
1354
|
return null;
|
|
1344
1355
|
}
|
|
1345
|
-
throw new Error(`No country data for '${
|
|
1356
|
+
throw new Error(`No country data for '${iso2}'`);
|
|
1346
1357
|
}
|
|
1347
1358
|
|
|
1348
1359
|
// select the given flag, update the placeholder, title, and the active list item
|
|
1349
1360
|
// Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
|
|
1350
|
-
_setFlag(
|
|
1361
|
+
_setFlag(iso2) {
|
|
1351
1362
|
const { allowDropdown, showSelectedDialCode, showFlags, countrySearch } = this.options;
|
|
1352
1363
|
|
|
1353
1364
|
const prevCountry = this.selectedCountryData.iso2
|
|
1354
1365
|
? this.selectedCountryData
|
|
1355
1366
|
: {};
|
|
1356
1367
|
|
|
1357
|
-
// do this first as it will throw an error and stop if
|
|
1358
|
-
this.selectedCountryData =
|
|
1359
|
-
? this._getCountryData(
|
|
1368
|
+
// do this first as it will throw an error and stop if iso2 is invalid
|
|
1369
|
+
this.selectedCountryData = iso2
|
|
1370
|
+
? this._getCountryData(iso2, false)
|
|
1360
1371
|
: {};
|
|
1361
1372
|
// update the defaultCountry - we only need the iso2 from now on, so just store that
|
|
1362
1373
|
if (this.selectedCountryData.iso2) {
|
|
@@ -1364,14 +1375,14 @@ class Iti {
|
|
|
1364
1375
|
}
|
|
1365
1376
|
|
|
1366
1377
|
if (showFlags) {
|
|
1367
|
-
const flagClass =
|
|
1378
|
+
const flagClass = iso2 ? `iti__${iso2}` : 'iti__globe';
|
|
1368
1379
|
this.selectedFlagInner.setAttribute(
|
|
1369
1380
|
"class",
|
|
1370
1381
|
`iti__flag ${flagClass}`
|
|
1371
1382
|
);
|
|
1372
1383
|
}
|
|
1373
1384
|
|
|
1374
|
-
this._setSelectedCountryFlagTitleAttribute(
|
|
1385
|
+
this._setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode);
|
|
1375
1386
|
|
|
1376
1387
|
if (showSelectedDialCode) {
|
|
1377
1388
|
const dialCode = this.selectedCountryData.dialCode
|
|
@@ -1400,14 +1411,14 @@ class Iti {
|
|
|
1400
1411
|
prevItem.classList.remove("iti__active");
|
|
1401
1412
|
prevItem.setAttribute("aria-selected", "false");
|
|
1402
1413
|
}
|
|
1403
|
-
if (
|
|
1414
|
+
if (iso2) {
|
|
1404
1415
|
// check if there is a preferred item first, else fall back to standard
|
|
1405
1416
|
const nextItem =
|
|
1406
1417
|
this.countryList.querySelector(
|
|
1407
|
-
`#iti-${this.id}__item-${
|
|
1418
|
+
`#iti-${this.id}__item-${iso2}-preferred`
|
|
1408
1419
|
) ||
|
|
1409
1420
|
this.countryList.querySelector(
|
|
1410
|
-
`#iti-${this.id}__item-${
|
|
1421
|
+
`#iti-${this.id}__item-${iso2}`
|
|
1411
1422
|
);
|
|
1412
1423
|
nextItem.setAttribute("aria-selected", "true");
|
|
1413
1424
|
nextItem.classList.add("iti__active");
|
|
@@ -1416,18 +1427,18 @@ class Iti {
|
|
|
1416
1427
|
}
|
|
1417
1428
|
|
|
1418
1429
|
// return if the flag has changed or not
|
|
1419
|
-
return prevCountry.iso2 !==
|
|
1430
|
+
return prevCountry.iso2 !== iso2;
|
|
1420
1431
|
}
|
|
1421
1432
|
|
|
1422
|
-
_setSelectedCountryFlagTitleAttribute(
|
|
1433
|
+
_setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode) {
|
|
1423
1434
|
if (!this.selectedFlag) {
|
|
1424
1435
|
return;
|
|
1425
1436
|
}
|
|
1426
1437
|
|
|
1427
1438
|
let title;
|
|
1428
|
-
if (
|
|
1439
|
+
if (iso2 && !showSelectedDialCode) {
|
|
1429
1440
|
title = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`;
|
|
1430
|
-
} else if (
|
|
1441
|
+
} else if (iso2) {
|
|
1431
1442
|
// For screen reader output, we don't want to include the dial code in the reader output twice
|
|
1432
1443
|
// so just use the selected country name here:
|
|
1433
1444
|
title = this.selectedCountryData.name;
|
|
@@ -1619,7 +1630,7 @@ class Iti {
|
|
|
1619
1630
|
numericChars += c;
|
|
1620
1631
|
// if current numericChars make a valid dial code
|
|
1621
1632
|
if (includeAreaCode) {
|
|
1622
|
-
if (this.
|
|
1633
|
+
if (this.dialCodeToIso2Map[numericChars]) {
|
|
1623
1634
|
// store the actual raw string (useful for matching later)
|
|
1624
1635
|
dialCode = number.substr(0, i + 1);
|
|
1625
1636
|
}
|
|
@@ -1631,7 +1642,7 @@ class Iti {
|
|
|
1631
1642
|
}
|
|
1632
1643
|
}
|
|
1633
1644
|
// stop searching as soon as we can - in this case when we hit max len
|
|
1634
|
-
if (numericChars.length === this.
|
|
1645
|
+
if (numericChars.length === this.dialCodeMaxLen) {
|
|
1635
1646
|
break;
|
|
1636
1647
|
}
|
|
1637
1648
|
}
|
|
@@ -1864,11 +1875,11 @@ class Iti {
|
|
|
1864
1875
|
}
|
|
1865
1876
|
|
|
1866
1877
|
// update the selected flag, and update the input val accordingly
|
|
1867
|
-
setCountry(
|
|
1868
|
-
const
|
|
1878
|
+
setCountry(iso2) {
|
|
1879
|
+
const iso2Lower = iso2.toLowerCase();
|
|
1869
1880
|
// check if already selected
|
|
1870
|
-
if (this.selectedCountryData.iso2 !==
|
|
1871
|
-
this._setFlag(
|
|
1881
|
+
if (this.selectedCountryData.iso2 !== iso2Lower) {
|
|
1882
|
+
this._setFlag(iso2Lower);
|
|
1872
1883
|
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
1873
1884
|
this._triggerCountryChange();
|
|
1874
1885
|
}
|
|
@@ -105,10 +105,10 @@ var getFlagsContainerElement = function(i) {
|
|
|
105
105
|
return i.parent().find(".iti__flag-container");
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
var selectFlag = function(
|
|
108
|
+
var selectFlag = function(iso2, i) {
|
|
109
109
|
i = i || input;
|
|
110
110
|
getSelectedFlagContainer(i)[0].click();
|
|
111
|
-
getListElement(i).find("li[data-country-code='" +
|
|
111
|
+
getListElement(i).find("li[data-country-code='" + iso2 + "']")[0].click();
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
var openCountryDropDown = function() {
|
|
@@ -4,12 +4,12 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
|
|
|
4
4
|
|
|
5
5
|
var input2,
|
|
6
6
|
iti2,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
afghanistanIso2Code = "af",
|
|
8
|
+
albaniaIso2Code = "al",
|
|
9
|
+
chinaIso2Code = "cn",
|
|
10
10
|
chinaDialCode = "+86",
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
koreaIso2Code = 'kr',
|
|
12
|
+
russiaIso2Code = 'ru';
|
|
13
13
|
|
|
14
14
|
beforeEach(function() {
|
|
15
15
|
intlSetup();
|
|
@@ -17,11 +17,11 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
|
|
|
17
17
|
input2 = $("<input>").wrap("div");
|
|
18
18
|
|
|
19
19
|
iti = window.intlTelInput(input[0], {
|
|
20
|
-
onlyCountries: [
|
|
20
|
+
onlyCountries: [afghanistanIso2Code, chinaIso2Code],
|
|
21
21
|
nationalMode: false,
|
|
22
22
|
});
|
|
23
23
|
iti2 = window.intlTelInput(input2[0], {
|
|
24
|
-
onlyCountries: [
|
|
24
|
+
onlyCountries: [albaniaIso2Code, chinaIso2Code, koreaIso2Code, russiaIso2Code],
|
|
25
25
|
nationalMode: false,
|
|
26
26
|
});
|
|
27
27
|
$("body").append(getParentElement(input)).append(getParentElement(input2));
|
|
@@ -40,21 +40,21 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
it("instances have different default countries selected", function() {
|
|
43
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
44
|
-
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${
|
|
43
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${afghanistanIso2Code}`);
|
|
44
|
+
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it("selecting an item from the first input dropdown only updates the flag on that input", function() {
|
|
48
|
-
selectFlag(
|
|
49
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
50
|
-
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${
|
|
48
|
+
selectFlag(chinaIso2Code);
|
|
49
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
|
|
50
|
+
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it("updating the number on the first input only updates the flag on that input", function() {
|
|
54
54
|
input.val(chinaDialCode + " 123456");
|
|
55
55
|
triggerKeyOnInput(" ");
|
|
56
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
57
|
-
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${
|
|
56
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
|
|
57
|
+
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
|
|
@@ -52,14 +52,14 @@ describe("using dropdown: init plugin on normal input with nationalMode=false, a
|
|
|
52
52
|
|
|
53
53
|
describe("selecting a new country item", function() {
|
|
54
54
|
|
|
55
|
-
var
|
|
55
|
+
var iso2Code = "ca";
|
|
56
56
|
|
|
57
57
|
beforeEach(function() {
|
|
58
|
-
getListElement().find("li[data-country-code='" +
|
|
58
|
+
getListElement().find("li[data-country-code='" + iso2Code + "']")[0].click();
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("updates the selected flag", function() {
|
|
62
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
62
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2Code}`);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
it("updates the dial code", function() {
|
|
@@ -69,7 +69,7 @@ describe("using dropdown: init plugin on normal input with nationalMode=false, a
|
|
|
69
69
|
// this was a bug
|
|
70
70
|
it("adding a space doesnt reset to the default country for that dial code", function() {
|
|
71
71
|
triggerKeyOnInput(" ");
|
|
72
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
72
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2Code}`);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
});
|
|
@@ -22,7 +22,7 @@ describe("getValidationError:", function() {
|
|
|
22
22
|
expect(iti.getValidationError()).toEqual(intlTelInputUtils.validationError.TOO_LONG);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it("returns the right error for a number with an invalid
|
|
25
|
+
it("returns the right error for a number with an invalid iso2 code", function() {
|
|
26
26
|
iti.setNumber("+969");
|
|
27
27
|
expect(iti.getValidationError()).toEqual(intlTelInputUtils.validationError.INVALID_COUNTRY_CODE);
|
|
28
28
|
});
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
describe("setCountry: init plugin and calling public method setCountry()", function() {
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var iso2 = "gb";
|
|
6
6
|
|
|
7
7
|
beforeEach(function() {
|
|
8
8
|
intlSetup();
|
|
9
9
|
input = $("<input>").wrap("div");
|
|
10
10
|
iti = window.intlTelInput(input[0]);
|
|
11
|
-
iti.setCountry(
|
|
11
|
+
iti.setCountry(iso2);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
afterEach(function() {
|
|
@@ -16,7 +16,7 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it("updates the selected flag", function() {
|
|
19
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
19
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2}`);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("does not insert the dial code", function() {
|
|
@@ -30,7 +30,7 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
|
|
|
30
30
|
showFlags: true,
|
|
31
31
|
showSelectedDialCode: false,
|
|
32
32
|
});
|
|
33
|
-
iti.setCountry(
|
|
33
|
+
iti.setCountry(iso2);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
it("has the country name and dial code in the flag's title", function() {
|
|
@@ -44,27 +44,12 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
|
|
|
44
44
|
showFlags: true,
|
|
45
45
|
showSelectedDialCode: true,
|
|
46
46
|
});
|
|
47
|
-
iti.setCountry(
|
|
47
|
+
iti.setCountry(iso2);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it("has the country name but not the dial code in the flag's title", function() {
|
|
51
51
|
expect(getSelectedFlagContainer().attr("title")).toEqual("United Kingdom");
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// setCountry errors out when country code is undefined, so we can likely remove this scenario and make country code a required param
|
|
57
|
-
describe("when countryCode is falsey", function() {
|
|
58
|
-
// beforeEach(function() {
|
|
59
|
-
// iti = window.intlTelInput(input[0], {
|
|
60
|
-
// showFlags: true,
|
|
61
|
-
// });
|
|
62
|
-
// iti.setCountry();
|
|
63
|
-
// });
|
|
64
|
-
|
|
65
|
-
it("sets the flag's title as Unknown", function() {
|
|
66
|
-
// expect(getSelectedFlagContainer().attr("title")).toEqual("Unknown");
|
|
67
|
-
});
|
|
68
|
-
})
|
|
69
54
|
});
|
|
70
55
|
});
|
|
@@ -17,18 +17,18 @@ describe("onlyCountries option:", function() {
|
|
|
17
17
|
|
|
18
18
|
describe("init plugin with onlyCountries set to japan, china and korea", function() {
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var chinaIso2Code = "cn";
|
|
21
21
|
|
|
22
22
|
beforeEach(function() {
|
|
23
23
|
// China and Japan (note that none of the default preferredCountries are included here, so wont be in the list)
|
|
24
|
-
onlyCountries = ['jp',
|
|
24
|
+
onlyCountries = ['jp', chinaIso2Code, 'kr'];
|
|
25
25
|
iti = window.intlTelInput(input[0], {
|
|
26
26
|
onlyCountries: onlyCountries,
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
it("defaults to the first onlyCountries alphabetically", function() {
|
|
31
|
-
expect(getSelectedFlagElement()).toHaveClass(`iti__${
|
|
31
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
it("has the right number of list items", function() {
|