intl-tel-input 17.0.20 → 18.0.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.
- package/CHANGELOG.md +19 -15
- package/README.md +14 -14
- package/build/css/intlTelInput.css +16 -5
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +2 -2
- package/build/js/data.min.js +2 -2
- package/build/js/intlTelInput-jquery.js +97 -49
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +97 -49
- package/build/js/intlTelInput.min.js +3 -3
- package/build/js/utils.js +198 -198
- package/composer.json +1 -1
- package/demo.html +6 -6
- package/demo_rtl.html +47 -0
- package/examples/gen/country-sync.html +6 -6
- package/examples/gen/default-country-ip.html +5 -5
- package/examples/gen/display-number.html +5 -5
- package/examples/gen/hidden-input.html +5 -5
- package/examples/gen/init-promise.html +5 -5
- package/examples/gen/is-valid-number.html +6 -6
- package/examples/gen/js/countrySync.js +1 -1
- package/examples/gen/js/defaultCountryIp.js +1 -1
- package/examples/gen/js/displayNumber.js +1 -1
- package/examples/gen/js/hiddenInput.js +1 -1
- package/examples/gen/js/initPromise.js +1 -1
- package/examples/gen/js/isValidNumber.js +1 -1
- package/examples/gen/js/modifyCountryData.js +1 -1
- package/examples/gen/js/multipleInstances.js +2 -2
- package/examples/gen/js/nationalMode.js +1 -1
- package/examples/gen/js/onlyCountriesEurope.js +1 -1
- package/examples/gen/modify-country-data.html +5 -5
- package/examples/gen/multiple-instances.html +6 -6
- package/examples/gen/national-mode.html +5 -5
- package/examples/gen/only-countries-europe.html +5 -5
- package/package.json +1 -1
- package/spec.html +1 -1
- package/src/css/intlTelInput.scss +23 -6
- package/src/js/data.js +1 -1
- package/src/js/intlTelInput.js +53 -50
- package/src/spec/tests/core/dropdownShortcuts.js +3 -2
- package/src/spec/tests/core/multipleInstances.js +8 -7
- package/src/spec/tests/core/usingDropdown.js +30 -10
- package/src/spec/tests/methods/destroy.js +2 -2
- package/src/spec/tests/options/allowDropdown.js +8 -0
- package/src/spec/tests/options/{autoHideDialCode.js → autoInsertDialCode.js} +18 -28
- package/src/spec/tests/options/separateDialCode.js +42 -2
package/src/js/intlTelInput.js
CHANGED
|
@@ -15,8 +15,9 @@ let id = 0;
|
|
|
15
15
|
const defaults = {
|
|
16
16
|
// whether or not to allow the dropdown
|
|
17
17
|
allowDropdown: true,
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// auto insert dial code (A) on init, (B) on user selecting a country, (C) on calling setCountry
|
|
19
|
+
// also listen for blur/submit and auto remove dial code if that's all there is
|
|
20
|
+
autoInsertDialCode: false,
|
|
20
21
|
// add a placeholder in the input with an example number for the selected country
|
|
21
22
|
autoPlaceholder: 'polite',
|
|
22
23
|
// modify the parentClass
|
|
@@ -37,7 +38,7 @@ const defaults = {
|
|
|
37
38
|
initialCountry: '',
|
|
38
39
|
// localized country names e.g. { 'de': 'Deutschland' }
|
|
39
40
|
localizedCountries: null,
|
|
40
|
-
//
|
|
41
|
+
// deal with national numbers instead of international numbers
|
|
41
42
|
nationalMode: true,
|
|
42
43
|
// display only these countries
|
|
43
44
|
onlyCountries: [],
|
|
@@ -45,7 +46,7 @@ const defaults = {
|
|
|
45
46
|
placeholderNumberType: 'MOBILE',
|
|
46
47
|
// the countries at the top of the list. defaults to united states and united kingdom
|
|
47
48
|
preferredCountries: ['us', 'gb'],
|
|
48
|
-
// display the country dial code next to the selected flag
|
|
49
|
+
// display the country dial code next to the selected flag
|
|
49
50
|
separateDialCode: false,
|
|
50
51
|
// specify the path to the libphonenumber script to enable validation/formatting
|
|
51
52
|
utilsScript: '',
|
|
@@ -94,15 +95,11 @@ class Iti {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
_init() {
|
|
97
|
-
// if in nationalMode,
|
|
98
|
-
if (this.options.nationalMode) this.options.
|
|
98
|
+
// if in nationalMode, do not insert dial codes
|
|
99
|
+
if (this.options.nationalMode) this.options.autoInsertDialCode = false;
|
|
99
100
|
|
|
100
|
-
// if separateDialCode
|
|
101
|
-
|
|
102
|
-
// dial code next to them)
|
|
103
|
-
if (this.options.separateDialCode) {
|
|
104
|
-
this.options.autoHideDialCode = this.options.nationalMode = false;
|
|
105
|
-
}
|
|
101
|
+
// if separateDialCode enabled, do not insert dial codes
|
|
102
|
+
if (this.options.separateDialCode) this.options.autoInsertDialCode = false;
|
|
106
103
|
|
|
107
104
|
// we cannot just test screen size as some smartphones/website meta tags will report desktop
|
|
108
105
|
// resolutions
|
|
@@ -151,7 +148,7 @@ class Iti {
|
|
|
151
148
|
// set the initial state of the input value and the selected flag
|
|
152
149
|
this._setInitialState();
|
|
153
150
|
|
|
154
|
-
// start all of the event listeners:
|
|
151
|
+
// start all of the event listeners: autoInsertDialCode, input keydown, selectedFlag click
|
|
155
152
|
this._initListeners();
|
|
156
153
|
|
|
157
154
|
// utils script, and auto country
|
|
@@ -237,7 +234,9 @@ class Iti {
|
|
|
237
234
|
|
|
238
235
|
// sort by country name
|
|
239
236
|
_countryNameSort(a, b) {
|
|
240
|
-
|
|
237
|
+
if (a.name < b.name) return -1;
|
|
238
|
+
if (a.name > b.name) return 1;
|
|
239
|
+
return 0;
|
|
241
240
|
}
|
|
242
241
|
|
|
243
242
|
|
|
@@ -329,22 +328,35 @@ class Iti {
|
|
|
329
328
|
wrapper.appendChild(this.telInput);
|
|
330
329
|
|
|
331
330
|
// selected flag (displayed to left of input)
|
|
331
|
+
// using Aria tags for "Select-Only Combobox Example"
|
|
332
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
|
|
332
333
|
this.selectedFlag = this._createEl('div', {
|
|
333
334
|
class: 'iti__selected-flag',
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
...(this.options.allowDropdown && {
|
|
336
|
+
role: 'combobox',
|
|
337
|
+
'aria-haspopup': 'listbox',
|
|
338
|
+
'aria-controls': `iti-${this.id}__country-listbox`,
|
|
339
|
+
'aria-owns': `iti-${this.id}__country-listbox`,
|
|
340
|
+
'aria-expanded': 'false',
|
|
341
|
+
'aria-label': 'Telephone country code',
|
|
342
|
+
}),
|
|
338
343
|
}, this.flagsContainer);
|
|
339
344
|
this.selectedFlagInner = this._createEl('div', { class: 'iti__flag' }, this.selectedFlag);
|
|
340
345
|
|
|
346
|
+
if (this.telInput.disabled) {
|
|
347
|
+
this.selectedFlag.setAttribute('aria-disabled', 'true');
|
|
348
|
+
}
|
|
349
|
+
|
|
341
350
|
if (this.options.separateDialCode) {
|
|
342
351
|
this.selectedDialCode = this._createEl('div', { class: 'iti__selected-dial-code' }, this.selectedFlag);
|
|
343
352
|
}
|
|
344
353
|
|
|
345
354
|
if (this.options.allowDropdown) {
|
|
346
|
-
|
|
347
|
-
|
|
355
|
+
if (!this.telInput.disabled) {
|
|
356
|
+
// make element focusable and tab navigable
|
|
357
|
+
this.selectedFlag.setAttribute('tabindex', '0');
|
|
358
|
+
}
|
|
359
|
+
|
|
348
360
|
this.dropdownArrow = this._createEl('div', { class: 'iti__arrow' }, this.selectedFlag);
|
|
349
361
|
|
|
350
362
|
// country dropdown: preferred countries, then divider, then all countries
|
|
@@ -431,9 +443,7 @@ class Iti {
|
|
|
431
443
|
const isRegionlessNanp = this._isRegionlessNanp(val);
|
|
432
444
|
const {
|
|
433
445
|
initialCountry,
|
|
434
|
-
|
|
435
|
-
autoHideDialCode,
|
|
436
|
-
separateDialCode,
|
|
446
|
+
autoInsertDialCode,
|
|
437
447
|
} = this.options;
|
|
438
448
|
|
|
439
449
|
// if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
|
|
@@ -458,8 +468,8 @@ class Iti {
|
|
|
458
468
|
}
|
|
459
469
|
}
|
|
460
470
|
|
|
461
|
-
// if empty and
|
|
462
|
-
if (!val &&
|
|
471
|
+
// if empty and autoInsertDialCode then insert the dial code
|
|
472
|
+
if (!val && autoInsertDialCode) {
|
|
463
473
|
this.telInput.value = `+${this.selectedCountryData.dialCode}`;
|
|
464
474
|
}
|
|
465
475
|
}
|
|
@@ -473,7 +483,7 @@ class Iti {
|
|
|
473
483
|
// initialise the main event listeners: input keyup, and click selected flag
|
|
474
484
|
_initListeners() {
|
|
475
485
|
this._initKeyListeners();
|
|
476
|
-
if (this.options.
|
|
486
|
+
if (this.options.autoInsertDialCode) this._initBlurListeners();
|
|
477
487
|
if (this.options.allowDropdown) this._initDropdownListeners();
|
|
478
488
|
if (this.hiddenInput) this._initHiddenInputListener();
|
|
479
489
|
}
|
|
@@ -614,7 +624,7 @@ class Iti {
|
|
|
614
624
|
}
|
|
615
625
|
|
|
616
626
|
|
|
617
|
-
// listen for blur/submit (for
|
|
627
|
+
// listen for blur/submit (for autoInsertDialCode feature)
|
|
618
628
|
_initBlurListeners() {
|
|
619
629
|
// on blur or form submit: if just a dial code then remove it
|
|
620
630
|
this._handleSubmitOrBlurEvent = () => {
|
|
@@ -840,8 +850,7 @@ class Iti {
|
|
|
840
850
|
_updateValFromNumber(originalNumber) {
|
|
841
851
|
let number = originalNumber;
|
|
842
852
|
if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
|
|
843
|
-
const useNational = (!this.options.separateDialCode
|
|
844
|
-
&& (this.options.nationalMode || number.charAt(0) !== '+'));
|
|
853
|
+
const useNational = (this.options.nationalMode || (number.charAt(0) !== '+' && !this.options.separateDialCode));
|
|
845
854
|
const { NATIONAL, INTERNATIONAL } = intlTelInputUtils.numberFormat;
|
|
846
855
|
const format = useNational ? NATIONAL : INTERNATIONAL;
|
|
847
856
|
number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
|
|
@@ -862,13 +871,13 @@ class Iti {
|
|
|
862
871
|
// dial code, so fine to ignore this bit
|
|
863
872
|
let number = originalNumber;
|
|
864
873
|
const selectedDialCode = this.selectedCountryData.dialCode;
|
|
865
|
-
const isNanp = selectedDialCode === '1';
|
|
874
|
+
const isNanp = (selectedDialCode === '1');
|
|
866
875
|
if (number && this.options.nationalMode && isNanp && number.charAt(0) !== '+') {
|
|
867
876
|
if (number.charAt(0) !== '1') number = `1${number}`;
|
|
868
877
|
number = `+${number}`;
|
|
869
878
|
}
|
|
870
879
|
|
|
871
|
-
//
|
|
880
|
+
// if separateDialCode enabled, then consider the selected dial code to be part of the number
|
|
872
881
|
if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== '+') {
|
|
873
882
|
number = `+${selectedDialCode}${number}`;
|
|
874
883
|
}
|
|
@@ -936,6 +945,7 @@ class Iti {
|
|
|
936
945
|
if (prevItem) prevItem.classList.remove('iti__highlight');
|
|
937
946
|
this.highlightedItem = listItem;
|
|
938
947
|
this.highlightedItem.classList.add('iti__highlight');
|
|
948
|
+
this.selectedFlag.setAttribute('aria-activedescendant', listItem.getAttribute('id'));
|
|
939
949
|
|
|
940
950
|
if (shouldFocus) this.highlightedItem.focus();
|
|
941
951
|
}
|
|
@@ -975,7 +985,7 @@ class Iti {
|
|
|
975
985
|
this.selectedFlag.setAttribute('title', title);
|
|
976
986
|
|
|
977
987
|
if (this.options.separateDialCode) {
|
|
978
|
-
const dialCode =
|
|
988
|
+
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : '';
|
|
979
989
|
this.selectedDialCode.innerHTML = dialCode;
|
|
980
990
|
// offsetWidth is zero if input is in a hidden container during initialisation
|
|
981
991
|
const selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
|
|
@@ -1000,7 +1010,6 @@ class Iti {
|
|
|
1000
1010
|
nextItem.setAttribute('aria-selected', 'true');
|
|
1001
1011
|
nextItem.classList.add('iti__active');
|
|
1002
1012
|
this.activeItem = nextItem;
|
|
1003
|
-
this.selectedFlag.setAttribute('aria-activedescendant', nextItem.getAttribute('id'));
|
|
1004
1013
|
}
|
|
1005
1014
|
}
|
|
1006
1015
|
|
|
@@ -1052,7 +1061,7 @@ class Iti {
|
|
|
1052
1061
|
const flagChanged = this._setFlag(listItem.getAttribute('data-country-code'));
|
|
1053
1062
|
this._closeDropdown();
|
|
1054
1063
|
|
|
1055
|
-
this._updateDialCode(listItem.getAttribute('data-dial-code')
|
|
1064
|
+
this._updateDialCode(listItem.getAttribute('data-dial-code'));
|
|
1056
1065
|
|
|
1057
1066
|
// focus the input
|
|
1058
1067
|
this.telInput.focus();
|
|
@@ -1071,6 +1080,8 @@ class Iti {
|
|
|
1071
1080
|
_closeDropdown() {
|
|
1072
1081
|
this.countryList.classList.add('iti__hide');
|
|
1073
1082
|
this.selectedFlag.setAttribute('aria-expanded', 'false');
|
|
1083
|
+
this.selectedFlag.removeAttribute('aria-activedescendant');
|
|
1084
|
+
|
|
1074
1085
|
// update the arrow
|
|
1075
1086
|
this.dropdownArrow.classList.remove('iti__arrow--up');
|
|
1076
1087
|
|
|
@@ -1119,7 +1130,7 @@ class Iti {
|
|
|
1119
1130
|
|
|
1120
1131
|
// replace any existing dial code with the new one
|
|
1121
1132
|
// Note: called from _selectListItem and setCountry
|
|
1122
|
-
_updateDialCode(newDialCodeBare
|
|
1133
|
+
_updateDialCode(newDialCodeBare) {
|
|
1123
1134
|
const inputVal = this.telInput.value;
|
|
1124
1135
|
// save having to pass this every time
|
|
1125
1136
|
const newDialCode = `+${newDialCodeBare}`;
|
|
@@ -1136,24 +1147,16 @@ class Iti {
|
|
|
1136
1147
|
// (no way to determine where the invalid dial code ends and the rest of the number begins)
|
|
1137
1148
|
newNumber = newDialCode;
|
|
1138
1149
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
return;
|
|
1142
|
-
} else {
|
|
1143
|
-
// nationalMode is disabled
|
|
1150
|
+
this.telInput.value = newNumber;
|
|
1151
|
+
} else if (this.options.autoInsertDialCode) {
|
|
1144
1152
|
if (inputVal) {
|
|
1145
1153
|
// there is an existing value with no dial code: prefix the new dial code
|
|
1146
1154
|
newNumber = newDialCode + inputVal;
|
|
1147
|
-
} else if (hasSelectedListItem || !this.options.autoHideDialCode) {
|
|
1148
|
-
// no existing value and either they've just selected a list item, or autoHideDialCode is
|
|
1149
|
-
// disabled: insert new dial code
|
|
1150
|
-
newNumber = newDialCode;
|
|
1151
1155
|
} else {
|
|
1152
|
-
|
|
1156
|
+
newNumber = newDialCode;
|
|
1153
1157
|
}
|
|
1158
|
+
this.telInput.value = newNumber;
|
|
1154
1159
|
}
|
|
1155
|
-
|
|
1156
|
-
this.telInput.value = newNumber;
|
|
1157
1160
|
}
|
|
1158
1161
|
|
|
1159
1162
|
|
|
@@ -1296,8 +1299,8 @@ class Iti {
|
|
|
1296
1299
|
// unbind hiddenInput listeners
|
|
1297
1300
|
if (this.hiddenInput && form) form.removeEventListener('submit', this._handleHiddenInputSubmit);
|
|
1298
1301
|
|
|
1299
|
-
// unbind
|
|
1300
|
-
if (this.options.
|
|
1302
|
+
// unbind autoInsertDialCode listeners
|
|
1303
|
+
if (this.options.autoInsertDialCode) {
|
|
1301
1304
|
if (form) form.removeEventListener('submit', this._handleSubmitOrBlurEvent);
|
|
1302
1305
|
this.telInput.removeEventListener('blur', this._handleSubmitOrBlurEvent);
|
|
1303
1306
|
}
|
|
@@ -1377,7 +1380,7 @@ class Iti {
|
|
|
1377
1380
|
// check if already selected
|
|
1378
1381
|
if (!this.selectedFlagInner.classList.contains(`iti__${countryCode}`)) {
|
|
1379
1382
|
this._setFlag(countryCode);
|
|
1380
|
-
this._updateDialCode(this.selectedCountryData.dialCode
|
|
1383
|
+
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
1381
1384
|
this._triggerCountryChange();
|
|
1382
1385
|
}
|
|
1383
1386
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
describe("dropdown shortcuts: init plugin (with nationalMode=false) to test keyboard shortcuts", function() {
|
|
3
|
+
describe("dropdown shortcuts: init plugin (with nationalMode=false, autoInsertDialCode=true) to test keyboard shortcuts", function() {
|
|
4
4
|
|
|
5
5
|
beforeEach(function() {
|
|
6
6
|
intlSetup();
|
|
7
7
|
input = $("<input>").appendTo("body");
|
|
8
8
|
iti = window.intlTelInput(input[0], {
|
|
9
|
-
nationalMode: false
|
|
9
|
+
nationalMode: false,
|
|
10
|
+
autoInsertDialCode: true,
|
|
10
11
|
});
|
|
11
12
|
});
|
|
12
13
|
|
|
@@ -7,20 +7,21 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
|
|
|
7
7
|
afghanistanCountryCode = "af",
|
|
8
8
|
albaniaCountryCode = "al",
|
|
9
9
|
chinaCountryCode = "cn",
|
|
10
|
-
chinaDialCode = "+86"
|
|
10
|
+
chinaDialCode = "+86",
|
|
11
|
+
koreaCountryCode = 'kr',
|
|
12
|
+
russiaCountryCode = 'ru';
|
|
11
13
|
|
|
12
14
|
beforeEach(function() {
|
|
13
15
|
intlSetup();
|
|
14
16
|
input = $("<input>").wrap("div");
|
|
15
17
|
input2 = $("<input>").wrap("div");
|
|
16
|
-
|
|
18
|
+
|
|
17
19
|
iti = window.intlTelInput(input[0], {
|
|
18
|
-
onlyCountries: [
|
|
20
|
+
onlyCountries: [afghanistanCountryCode, chinaCountryCode],
|
|
19
21
|
nationalMode: false,
|
|
20
22
|
});
|
|
21
|
-
// korea, china and russia
|
|
22
23
|
iti2 = window.intlTelInput(input2[0], {
|
|
23
|
-
onlyCountries: [
|
|
24
|
+
onlyCountries: [albaniaCountryCode, chinaCountryCode, koreaCountryCode, russiaCountryCode],
|
|
24
25
|
nationalMode: false,
|
|
25
26
|
});
|
|
26
27
|
$("body").append(getParentElement(input)).append(getParentElement(input2));
|
|
@@ -45,8 +46,8 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
|
|
|
45
46
|
|
|
46
47
|
it("selecting an item from the first input dropdown only updates the flag on that input", function() {
|
|
47
48
|
selectFlag(chinaCountryCode);
|
|
48
|
-
expect(
|
|
49
|
-
expect(
|
|
49
|
+
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
|
|
50
|
+
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
it("updating the number on the first input only updates the flag on that input", function() {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
3
|
+
describe("using dropdown: init plugin on normal input with nationalMode=false, autoInsertDialCode=true", function() {
|
|
4
4
|
|
|
5
5
|
beforeEach(function() {
|
|
6
6
|
intlSetup();
|
|
7
7
|
input = $("<input>").appendTo("body");
|
|
8
|
-
// nationalMode=false because we're playing with dial codes
|
|
8
|
+
// nationalMode=false and autoInsertDialCode=true because we're playing with dial codes
|
|
9
9
|
iti = window.intlTelInput(input[0], {
|
|
10
|
-
nationalMode: false
|
|
10
|
+
nationalMode: false,
|
|
11
|
+
autoInsertDialCode: true,
|
|
11
12
|
});
|
|
12
13
|
});
|
|
13
14
|
|
|
@@ -15,19 +16,16 @@ describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
|
15
16
|
intlTeardown();
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
it("
|
|
19
|
+
it("clicking the selected flag opens the dropdown", function() {
|
|
19
20
|
getSelectedFlagContainer()[0].click();
|
|
20
21
|
expect(getListElement()).toBeVisible();
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
it("
|
|
24
|
-
|
|
25
|
-
getSelectedFlagContainer()
|
|
26
|
-
expect(getListElement()).not.toBeVisible();
|
|
24
|
+
it("allows focusing the dropdown using the keyboard", function() {
|
|
25
|
+
expect(getSelectedFlagContainer().attr('tabindex')).toEqual('0');
|
|
26
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr('aria-disabled');
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
29
|
describe("clicking the selected flag to open the dropdown", function() {
|
|
32
30
|
|
|
33
31
|
beforeEach(function() {
|
|
@@ -79,3 +77,25 @@ describe("using dropdown: init plugin with nationalMode=false", function() {
|
|
|
79
77
|
});
|
|
80
78
|
|
|
81
79
|
});
|
|
80
|
+
|
|
81
|
+
describe("using dropdown: disabled input", () => {
|
|
82
|
+
beforeEach(function() {
|
|
83
|
+
intlSetup();
|
|
84
|
+
input = $("<input disabled>").appendTo("body");
|
|
85
|
+
iti = window.intlTelInput(input[0]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(function() {
|
|
89
|
+
intlTeardown();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("prevents the user from opening the dropdown using the keyboard", function() {
|
|
93
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr('tabindex');
|
|
94
|
+
expect(getSelectedFlagContainer().attr('aria-disabled')).toEqual('true');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("clicking the selected flag does not open the dropdown", function() {
|
|
98
|
+
getSelectedFlagContainer()[0].click();
|
|
99
|
+
expect(getListElement()).not.toBeVisible();
|
|
100
|
+
});
|
|
101
|
+
})
|
|
@@ -52,14 +52,14 @@ describe("destroy: init plugin to test public method destroy", function() {
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
describe("destroy: init plugin with nationalMode=false and
|
|
55
|
+
describe("destroy: init plugin with nationalMode=false and autoInsertDialCode=true", function() {
|
|
56
56
|
|
|
57
57
|
beforeEach(function() {
|
|
58
58
|
intlSetup();
|
|
59
59
|
input = $("<input>").wrap("div");
|
|
60
60
|
iti = window.intlTelInput(input[0], {
|
|
61
61
|
nationalMode: false,
|
|
62
|
-
|
|
62
|
+
autoInsertDialCode: true
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
@@ -24,6 +24,10 @@ describe("allowDropdown:", function() {
|
|
|
24
24
|
expect(getListElement()).not.toExist();
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
if("Should not add role[combox]", function() {
|
|
28
|
+
expect(getSelectedFlagContainer()).not.toHaveAttr("role", "combobox");
|
|
29
|
+
});
|
|
30
|
+
|
|
27
31
|
it("typing a different dial code updates the flag", function() {
|
|
28
32
|
input.val("+4");
|
|
29
33
|
triggerKeyOnInput("4");
|
|
@@ -60,6 +64,10 @@ describe("allowDropdown:", function() {
|
|
|
60
64
|
});
|
|
61
65
|
});
|
|
62
66
|
|
|
67
|
+
if("Should have role[combox]", function() {
|
|
68
|
+
expect(getSelectedFlagContainer()).toHaveAttr("role", "combobox");
|
|
69
|
+
});
|
|
70
|
+
|
|
63
71
|
it("shows the arrow and generate the dropdown markup", function() {
|
|
64
72
|
expect(getSelectedFlagContainer().find(".iti__arrow")).toExist();
|
|
65
73
|
expect(getListElement()).toExist();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
describe("
|
|
3
|
+
describe("autoInsertDialCode option:", function() {
|
|
4
4
|
|
|
5
5
|
var defaultDialCode = "+1";
|
|
6
6
|
|
|
@@ -16,16 +16,21 @@ describe("autoHideDialCode option:", function() {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
describe("init plugin with
|
|
19
|
+
describe("init plugin with autoInsertDialCode=true and nationalMode=false", function() {
|
|
20
20
|
|
|
21
21
|
beforeEach(function() {
|
|
22
22
|
iti = window.intlTelInput(input[0], {
|
|
23
|
-
|
|
23
|
+
autoInsertDialCode: true,
|
|
24
24
|
nationalMode: false
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("
|
|
28
|
+
it("automatically inserts the default dial code", function() {
|
|
29
|
+
expect(getInputVal()).toEqual(defaultDialCode);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("blurring the input removes it", function() {
|
|
33
|
+
triggerInputEvent("blur");
|
|
29
34
|
expect(getInputVal()).toEqual("");
|
|
30
35
|
});
|
|
31
36
|
|
|
@@ -56,9 +61,7 @@ describe("autoHideDialCode option:", function() {
|
|
|
56
61
|
input.val(number);
|
|
57
62
|
});
|
|
58
63
|
|
|
59
|
-
it("
|
|
60
|
-
triggerInputEvent("focus");
|
|
61
|
-
expect(getInputVal()).toEqual(number);
|
|
64
|
+
it("blurring the input doesn't change it", function() {
|
|
62
65
|
triggerInputEvent("blur");
|
|
63
66
|
expect(getInputVal()).toEqual(number);
|
|
64
67
|
});
|
|
@@ -68,40 +71,27 @@ describe("autoHideDialCode option:", function() {
|
|
|
68
71
|
});
|
|
69
72
|
|
|
70
73
|
|
|
71
|
-
describe("init plugin with
|
|
74
|
+
describe("init plugin with autoInsertDialCode=false and nationalMode=false", function() {
|
|
72
75
|
|
|
73
76
|
beforeEach(function() {
|
|
74
77
|
iti = window.intlTelInput(input[0], {
|
|
75
|
-
|
|
78
|
+
autoInsertDialCode: false,
|
|
76
79
|
nationalMode: false
|
|
77
80
|
});
|
|
78
81
|
});
|
|
79
82
|
|
|
80
|
-
it("automatically
|
|
81
|
-
expect(getInputVal()).toEqual(
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("focusing and bluring the input dont change the val", function() {
|
|
85
|
-
triggerInputEvent("focus");
|
|
86
|
-
expect(getInputVal()).toEqual(defaultDialCode);
|
|
87
|
-
triggerInputEvent("blur");
|
|
88
|
-
expect(getInputVal()).toEqual(defaultDialCode);
|
|
83
|
+
it("does not automatically insert the default dial code", function() {
|
|
84
|
+
expect(getInputVal()).toEqual("");
|
|
89
85
|
});
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
describe("with a phone number", function() {
|
|
93
|
-
|
|
94
|
-
var number = "+1 702 987 2345";
|
|
87
|
+
describe("selecting a country", function() {
|
|
95
88
|
|
|
96
89
|
beforeEach(function() {
|
|
97
|
-
|
|
90
|
+
selectFlag("gb");
|
|
98
91
|
});
|
|
99
92
|
|
|
100
|
-
it("
|
|
101
|
-
|
|
102
|
-
expect(getInputVal()).toEqual(number);
|
|
103
|
-
triggerInputEvent("blur");
|
|
104
|
-
expect(getInputVal()).toEqual(number);
|
|
93
|
+
it("does not add the dial code", function() {
|
|
94
|
+
expect(getInputVal()).toEqual("");
|
|
105
95
|
});
|
|
106
96
|
|
|
107
97
|
});
|
|
@@ -14,11 +14,12 @@ describe("separateDialCode:", function() {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// we test with "gb" because the ntl number is different to the intl number (aside from the dial code)
|
|
17
|
-
describe("init plugin with initialCountry=gb", function() {
|
|
17
|
+
describe("init plugin with initialCountry=gb and nationalMode=false", function() {
|
|
18
18
|
|
|
19
19
|
beforeEach(function() {
|
|
20
20
|
iti = window.intlTelInput(input[0], {
|
|
21
21
|
separateDialCode: true,
|
|
22
|
+
nationalMode: false,
|
|
22
23
|
initialCountry: "gb",
|
|
23
24
|
});
|
|
24
25
|
});
|
|
@@ -57,12 +58,49 @@ describe("separateDialCode:", function() {
|
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
describe("init plugin with initialCountry=gb and nationalMode=true", function() {
|
|
62
|
+
|
|
63
|
+
beforeEach(function() {
|
|
64
|
+
iti = window.intlTelInput(input[0], {
|
|
65
|
+
separateDialCode: true,
|
|
66
|
+
nationalMode: true,
|
|
67
|
+
initialCountry: "gb",
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("formats the placeholder correctly", function() {
|
|
72
|
+
// national format
|
|
73
|
+
expect(input.attr("placeholder")).toEqual("07400 123456");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
describe("calling setNumber to a valid intl number", function() {
|
|
78
|
+
|
|
79
|
+
beforeEach(function() {
|
|
80
|
+
iti.setNumber("+447400123456");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("formats the number correctly", function() {
|
|
84
|
+
// national format
|
|
85
|
+
expect(getInputVal()).toEqual("07400 123456");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("calling getNumber returns the full intl number", function() {
|
|
89
|
+
expect(iti.getNumber()).toEqual("+447400123456");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
// we test with "ca" (Canada) because we had some bugs with area codes
|
|
61
98
|
describe("init plugin with initialCountry=ca", function() {
|
|
62
99
|
|
|
63
100
|
beforeEach(function() {
|
|
64
101
|
iti = window.intlTelInput(input[0], {
|
|
65
102
|
separateDialCode: true,
|
|
103
|
+
nationalMode: false,
|
|
66
104
|
initialCountry: "ca",
|
|
67
105
|
});
|
|
68
106
|
});
|
|
@@ -88,6 +126,7 @@ describe("separateDialCode:", function() {
|
|
|
88
126
|
beforeEach(function() {
|
|
89
127
|
iti = window.intlTelInput(input[0], {
|
|
90
128
|
separateDialCode: true,
|
|
129
|
+
nationalMode: false,
|
|
91
130
|
initialCountry: "as",
|
|
92
131
|
});
|
|
93
132
|
});
|
|
@@ -112,6 +151,7 @@ describe("separateDialCode:", function() {
|
|
|
112
151
|
input.val("(922) 555-1234");
|
|
113
152
|
iti = window.intlTelInput(input[0], {
|
|
114
153
|
separateDialCode: true,
|
|
154
|
+
nationalMode: false,
|
|
115
155
|
initialCountry: "ru",
|
|
116
156
|
});
|
|
117
157
|
});
|