intl-tel-input 18.5.2 → 19.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.
Files changed (34) hide show
  1. package/README.md +42 -28
  2. package/build/css/demo.css +1 -1
  3. package/build/css/intlTelInput.css +28 -20
  4. package/build/js/data.js +1 -1
  5. package/build/js/data.min.js +1 -1
  6. package/build/js/intlTelInput-jquery.js +159 -154
  7. package/build/js/intlTelInput-jquery.min.js +3 -3
  8. package/build/js/intlTelInput.js +159 -154
  9. package/build/js/intlTelInput.min.js +3 -3
  10. package/composer.json +1 -1
  11. package/demo.html +5 -5
  12. package/grunt/replace.js +1 -7
  13. package/package.json +1 -1
  14. package/spec.html +6 -4
  15. package/src/css/demo.scss +1 -1
  16. package/src/css/intlTelInput.scss +41 -30
  17. package/src/js/intlTelInput.js +77 -128
  18. package/src/spec/helpers/helpers.js +23 -10
  19. package/src/spec/tests/core/countrychangeEvent.js +1 -1
  20. package/src/spec/tests/core/dropdownShortcuts.js +3 -2
  21. package/src/spec/tests/core/initialValues.js +2 -3
  22. package/src/spec/tests/methods/getSelectedCountryData.js +1 -1
  23. package/src/spec/tests/methods/isValidNumber.js +15 -32
  24. package/src/spec/tests/methods/isValidNumberPrecise.js +73 -0
  25. package/src/spec/tests/methods/setCountry.js +4 -4
  26. package/src/spec/tests/options/allowDropdown.js +3 -3
  27. package/src/spec/tests/options/autoInsertDialCode.js +1 -3
  28. package/src/spec/tests/options/autoPlaceholder.js +5 -5
  29. package/src/spec/tests/options/{customContainer.js → containerClass.js} +3 -3
  30. package/src/spec/tests/options/countrySearch.js +63 -0
  31. package/src/spec/tests/options/customPlaceholder.js +1 -1
  32. package/src/spec/tests/options/preferredCountries.js +3 -1
  33. package/src/spec/tests/options/{separateDialCode.js → showSelectedDialCode.js} +7 -7
  34. package/src/spec/tests/methods/isPossibleNumber.js +0 -56
@@ -24,50 +24,33 @@ describe("isValidNumber:", function() {
24
24
  expect(iti.isValidNumber()).toBeTruthy();
25
25
  });
26
26
 
27
- it("returns false for: invalid (too short) intl number", function() {
28
- iti.setNumber("+44 7733 123");
29
- expect(iti.isValidNumber()).toBeFalsy();
30
- });
31
-
32
- it("returns false for: possible but invalid (bad dial code) intl number", function() {
27
+ it("returns true for: possible but invalid (bad dial code) intl number", function() {
33
28
  iti.setNumber("+44 9999 123456");
34
- expect(iti.isValidNumber()).toBeFalsy();
35
- });
36
-
37
- it("returns null when utils script is not available", function() {
38
- delete window.intlTelInputUtils;
39
- iti.setNumber("+44 7733 123456");
40
- expect(iti.isValidNumber()).toBeNull();
41
- });
42
-
43
- });
44
-
45
-
46
- describe("init plugin with nationalMode=true and call public method isValidNumber", function() {
47
-
48
- beforeEach(function() {
49
- iti = window.intlTelInput(input[0], {
50
- nationalMode: true
51
- });
29
+ expect(iti.isValidNumber()).toBeTruthy();
52
30
  });
53
31
 
54
- it("returns false for: incorrect selected country, valid number", function() {
55
- iti.setNumber("07733 123456");
32
+ it("returns false for: invalid (too short by 2 digits) intl number", function() {
33
+ iti.setNumber("+44 7733 1234");
56
34
  expect(iti.isValidNumber()).toBeFalsy();
57
35
  });
58
36
 
59
- it("returns true for: correct selected country, valid number", function() {
60
- iti.setCountry("gb");
61
- iti.setNumber("07733 123456");
37
+ // guess this is a quirk of UK phone numbers that some valid ones are only 10 digits (e.g. 0773312345)
38
+ it("returns true for: invalid (too short by 1 digit) intl number", function() {
39
+ iti.setNumber("+44 7733 12345");
62
40
  expect(iti.isValidNumber()).toBeTruthy();
63
41
  });
64
42
 
65
- it("returns false for: correct selected country, invalid (too short) number", function() {
66
- iti.setCountry("gb");
67
- iti.setNumber("07733 123");
43
+ it("returns false for: invalid (too long) intl number", function() {
44
+ iti.setNumber("+44 7733 1234567");
68
45
  expect(iti.isValidNumber()).toBeFalsy();
69
46
  });
70
47
 
48
+ it("returns null when utils script is not available", function() {
49
+ delete window.intlTelInputUtils;
50
+ iti.setNumber("+44 7733 123456");
51
+ expect(iti.isValidNumber()).toBeNull();
52
+ });
53
+
71
54
  });
72
55
 
73
56
  });
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ describe("isValidNumberPrecise:", function() {
4
+
5
+ beforeEach(function() {
6
+ intlSetup(true);
7
+ input = $("<input>").wrap("div");
8
+ });
9
+
10
+ afterEach(function() {
11
+ intlTeardown();
12
+ });
13
+
14
+
15
+
16
+ describe("init plugin and call public method isValidNumberPrecise", function() {
17
+
18
+ beforeEach(function() {
19
+ iti = window.intlTelInput(input[0]);
20
+ });
21
+
22
+ it("returns true for: valid intl number", function() {
23
+ iti.setNumber("+44 7733 123456");
24
+ expect(iti.isValidNumberPrecise()).toBeTruthy();
25
+ });
26
+
27
+ it("returns false for: invalid (too short) intl number", function() {
28
+ iti.setNumber("+44 7733 123");
29
+ expect(iti.isValidNumberPrecise()).toBeFalsy();
30
+ });
31
+
32
+ it("returns false for: possible but invalid (bad dial code) intl number", function() {
33
+ iti.setNumber("+44 9999 123456");
34
+ expect(iti.isValidNumberPrecise()).toBeFalsy();
35
+ });
36
+
37
+ it("returns null when utils script is not available", function() {
38
+ delete window.intlTelInputUtils;
39
+ iti.setNumber("+44 7733 123456");
40
+ expect(iti.isValidNumberPrecise()).toBeNull();
41
+ });
42
+
43
+ });
44
+
45
+
46
+ describe("init plugin with nationalMode=true and call public method isValidNumberPrecise", function() {
47
+
48
+ beforeEach(function() {
49
+ iti = window.intlTelInput(input[0], {
50
+ nationalMode: true
51
+ });
52
+ });
53
+
54
+ it("returns false for: incorrect selected country, valid number", function() {
55
+ iti.setNumber("07733 123456");
56
+ expect(iti.isValidNumberPrecise()).toBeFalsy();
57
+ });
58
+
59
+ it("returns true for: correct selected country, valid number", function() {
60
+ iti.setCountry("gb");
61
+ iti.setNumber("07733 123456");
62
+ expect(iti.isValidNumberPrecise()).toBeTruthy();
63
+ });
64
+
65
+ it("returns false for: correct selected country, invalid (too short) number", function() {
66
+ iti.setCountry("gb");
67
+ iti.setNumber("07733 123");
68
+ expect(iti.isValidNumberPrecise()).toBeFalsy();
69
+ });
70
+
71
+ });
72
+
73
+ });
@@ -24,11 +24,11 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
24
24
  });
25
25
 
26
26
  describe("setting title attribute on flag container", function() {
27
- describe("when separateDialCode is false", function() {
27
+ describe("when showSelectedDialCode is false", function() {
28
28
  beforeEach(function() {
29
29
  iti = window.intlTelInput(input[0], {
30
30
  showFlags: true,
31
- separateDialCode: false,
31
+ showSelectedDialCode: false,
32
32
  });
33
33
  iti.setCountry(countryCode);
34
34
  });
@@ -38,11 +38,11 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
38
38
  });
39
39
  });
40
40
 
41
- describe("when separateDialCode is true", function() {
41
+ describe("when showSelectedDialCode is true", function() {
42
42
  beforeEach(function() {
43
43
  iti = window.intlTelInput(input[0], {
44
44
  showFlags: true,
45
- separateDialCode: true,
45
+ showSelectedDialCode: true,
46
46
  });
47
47
  iti.setCountry(countryCode);
48
48
  });
@@ -36,12 +36,12 @@ describe("allowDropdown:", function() {
36
36
 
37
37
  });
38
38
 
39
- describe("init plugin with allowDropdown=false and separateDialCode=true", function() {
39
+ describe("init plugin with allowDropdown=false and showSelectedDialCode=true", function() {
40
40
 
41
41
  beforeEach(function() {
42
42
  iti = window.intlTelInput(input[0], {
43
43
  allowDropdown: false,
44
- separateDialCode: true
44
+ showSelectedDialCode: true
45
45
  });
46
46
  });
47
47
 
@@ -51,7 +51,7 @@ describe("allowDropdown:", function() {
51
51
 
52
52
  it("shows selected dial code element", function() {
53
53
  expect(getSelectedDialCodeElement()).toExist();
54
- expect(getSelectedDialCodeElement().text()).toEqual('+1');
54
+ expect(getSelectedDialCodeElement().text()).toEqual(afghanistanDialCode);
55
55
  });
56
56
 
57
57
  });
@@ -2,8 +2,6 @@
2
2
 
3
3
  describe("autoInsertDialCode option:", function() {
4
4
 
5
- var defaultDialCode = "+1";
6
-
7
5
  beforeEach(function() {
8
6
  intlSetup();
9
7
 
@@ -26,7 +24,7 @@ describe("autoInsertDialCode option:", function() {
26
24
  });
27
25
 
28
26
  it("automatically inserts the default dial code", function() {
29
- expect(getInputVal()).toEqual(defaultDialCode);
27
+ expect(getInputVal()).toEqual(afghanistanDialCode);
30
28
  });
31
29
 
32
30
  it("blurring the input removes it", function() {
@@ -27,8 +27,8 @@ describe("autoPlaceholder: testing input with no placeholder", function() {
27
27
  });
28
28
  });
29
29
 
30
- it("sets the placeholder to an example national number for the US", function() {
31
- expect(input.attr("placeholder")).toEqual("(201) 555-0123");
30
+ it("sets the placeholder to an example national number for Afghanistan", function() {
31
+ expect(input.attr("placeholder")).toEqual("070 123 4567");
32
32
  });
33
33
 
34
34
  describe("changing the country to the UK", function() {
@@ -54,8 +54,8 @@ describe("autoPlaceholder: testing input with no placeholder", function() {
54
54
  });
55
55
  });
56
56
 
57
- it("sets the placeholder to an example international number for the US", function() {
58
- expect(input.attr("placeholder")).toEqual("+1 201-555-0123");
57
+ it("sets the placeholder to an example international number for Afghanistan", function() {
58
+ expect(input.attr("placeholder")).toEqual("+93 70 123 4567");
59
59
  });
60
60
 
61
61
  describe("changing the country to the UK", function() {
@@ -108,7 +108,7 @@ describe("autoPlaceholder: testing input with an initial placeholder", function(
108
108
  iti = window.intlTelInput(input[0], {
109
109
  autoPlaceholder: "aggressive"
110
110
  });
111
- expect(input.attr("placeholder")).toEqual("(201) 555-0123");
111
+ expect(input.attr("placeholder")).toEqual("070 123 4567");
112
112
  });
113
113
 
114
114
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- describe("customContainer option:", function() {
3
+ describe("containerClass option:", function() {
4
4
 
5
5
  beforeEach(function() {
6
6
  intlSetup();
@@ -12,11 +12,11 @@ describe("customContainer option:", function() {
12
12
  });
13
13
 
14
14
 
15
- describe("init plugin with customContainer", function() {
15
+ describe("init plugin with containerClass", function() {
16
16
 
17
17
  beforeEach(function() {
18
18
  iti = window.intlTelInput(input[0], {
19
- customContainer: 'cpc',
19
+ containerClass: 'cpc',
20
20
  });
21
21
  });
22
22
 
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ describe("countrySearch option:", function() {
4
+
5
+ beforeEach(function() {
6
+ jasmine.clock().install();
7
+ intlSetup();
8
+ input = $("<input>").appendTo("body");
9
+ });
10
+
11
+ afterEach(function() {
12
+ jasmine.clock().uninstall();
13
+ intlTeardown();
14
+ });
15
+
16
+
17
+
18
+ describe("init plugin with countrySearch disabled, and open dropdown", function() {
19
+
20
+ beforeEach(function() {
21
+ iti = window.intlTelInput(input[0], {
22
+ countrySearch: false,
23
+ });
24
+ getSelectedFlagContainer().click();
25
+ });
26
+
27
+ it("does not insert the search input", function() {
28
+ expect(getDropdownContent().find("input.iti__search-input")).not.toExist();
29
+ });
30
+
31
+ });
32
+
33
+
34
+
35
+ describe("init plugin with countrySearch enabled, and open dropdown", function() {
36
+
37
+ beforeEach(function() {
38
+ iti = window.intlTelInput(input[0], {
39
+ countrySearch: true,
40
+ });
41
+ getSelectedFlagContainer().click();
42
+ });
43
+
44
+ it("inserts the search input", function() {
45
+ expect(getDropdownContent().find("input.iti__search-input")).toExist();
46
+ });
47
+
48
+ it("shows all countries to start with", function() {
49
+ expect(getListLength()).toEqual(totalCountries);
50
+ });
51
+
52
+ it("typing 'x' shows 6 results, and hitting Enter selects Christmas Islands", function() {
53
+ const searchInput = getSearchInput();
54
+ triggerKeyOnInput('x', searchInput);
55
+ jasmine.clock().tick(100); // allow for the (intentional) 100ms delay on the search handler
56
+ expect(getListLength()).toEqual(6);
57
+ triggerKeyOnBody('Enter');
58
+ expect(getActiveListItem().attr("data-country-code")).toEqual("cx");
59
+ });
60
+
61
+ });
62
+
63
+ });
@@ -18,7 +18,7 @@ describe("customPlaceholder: init plugin with autoPlaceholder=polite and customP
18
18
  });
19
19
 
20
20
  it("sets the placeholder to the customised US number", function() {
21
- expect(input.attr("placeholder")).toEqual("e.g. (201) 555-0123");
21
+ expect(input.attr("placeholder")).toEqual("e.g. 070 123 4567");
22
22
  });
23
23
 
24
24
  it("selecting UK updates the placeholder", function() {
@@ -17,11 +17,12 @@ describe("preferredCountries option:", function() {
17
17
 
18
18
  beforeEach(function() {
19
19
  iti = window.intlTelInput(input[0], {
20
+ countrySearch: false,
20
21
  preferredCountries: [],
21
22
  });
22
23
  });
23
24
 
24
- it("defaults to the first country in the alphabet", function() {
25
+ it("defaults to the first country in the list", function() {
25
26
  // Afghanistan
26
27
  expect(getSelectedFlagElement()).toHaveClass("iti__af");
27
28
  });
@@ -42,6 +43,7 @@ describe("preferredCountries option:", function() {
42
43
  // United Kingdom
43
44
  preferredCountries = ['gb'];
44
45
  iti = window.intlTelInput(input[0], {
46
+ countrySearch: false,
45
47
  preferredCountries: preferredCountries,
46
48
  });
47
49
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- describe("separateDialCode:", function() {
3
+ describe("showSelectedDialCode:", function() {
4
4
 
5
5
  beforeEach(function() {
6
6
  intlSetup(true);
@@ -18,14 +18,14 @@ describe("separateDialCode:", function() {
18
18
 
19
19
  beforeEach(function() {
20
20
  iti = window.intlTelInput(input[0], {
21
- separateDialCode: true,
21
+ showSelectedDialCode: true,
22
22
  nationalMode: false,
23
23
  initialCountry: "gb",
24
24
  });
25
25
  });
26
26
 
27
27
  it("sets the classes properly", function() {
28
- expect(getParentElement()).toHaveClass("iti--separate-dial-code");
28
+ expect(getParentElement()).toHaveClass("iti--show-selected-dial-code");
29
29
  });
30
30
 
31
31
  it("displays the dial code next to the selected flag", function() {
@@ -62,7 +62,7 @@ describe("separateDialCode:", function() {
62
62
 
63
63
  beforeEach(function() {
64
64
  iti = window.intlTelInput(input[0], {
65
- separateDialCode: true,
65
+ showSelectedDialCode: true,
66
66
  nationalMode: true,
67
67
  initialCountry: "gb",
68
68
  });
@@ -99,7 +99,7 @@ describe("separateDialCode:", function() {
99
99
 
100
100
  beforeEach(function() {
101
101
  iti = window.intlTelInput(input[0], {
102
- separateDialCode: true,
102
+ showSelectedDialCode: true,
103
103
  nationalMode: false,
104
104
  initialCountry: "ca",
105
105
  });
@@ -125,7 +125,7 @@ describe("separateDialCode:", function() {
125
125
 
126
126
  beforeEach(function() {
127
127
  iti = window.intlTelInput(input[0], {
128
- separateDialCode: true,
128
+ showSelectedDialCode: true,
129
129
  nationalMode: false,
130
130
  initialCountry: "as",
131
131
  });
@@ -150,7 +150,7 @@ describe("separateDialCode:", function() {
150
150
  beforeEach(function() {
151
151
  input.val("(922) 555-1234");
152
152
  iti = window.intlTelInput(input[0], {
153
- separateDialCode: true,
153
+ showSelectedDialCode: true,
154
154
  nationalMode: false,
155
155
  initialCountry: "ru",
156
156
  });
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- describe("isPossibleNumber:", function() {
4
-
5
- beforeEach(function() {
6
- intlSetup(true);
7
- input = $("<input>").wrap("div");
8
- });
9
-
10
- afterEach(function() {
11
- intlTeardown();
12
- });
13
-
14
-
15
-
16
- describe("init plugin and call public method isPossibleNumber", function() {
17
-
18
- beforeEach(function() {
19
- iti = window.intlTelInput(input[0]);
20
- });
21
-
22
- it("returns true for: valid intl number", function() {
23
- iti.setNumber("+44 7733 123456");
24
- expect(iti.isPossibleNumber()).toBeTruthy();
25
- });
26
-
27
- it("returns true for: possible but invalid (bad dial code) intl number", function() {
28
- iti.setNumber("+44 9999 123456");
29
- expect(iti.isPossibleNumber()).toBeTruthy();
30
- });
31
-
32
- it("returns false for: invalid (too short by 2 digits) intl number", function() {
33
- iti.setNumber("+44 7733 1234");
34
- expect(iti.isPossibleNumber()).toBeFalsy();
35
- });
36
-
37
- // guess this is a quirk of UK phone numbers that some valid ones are only 10 digits (e.g. 0773312345)
38
- it("returns true for: invalid (too short by 1 digit) intl number", function() {
39
- iti.setNumber("+44 7733 12345");
40
- expect(iti.isPossibleNumber()).toBeTruthy();
41
- });
42
-
43
- it("returns false for: invalid (too long) intl number", function() {
44
- iti.setNumber("+44 7733 1234567");
45
- expect(iti.isPossibleNumber()).toBeFalsy();
46
- });
47
-
48
- it("returns null when utils script is not available", function() {
49
- delete window.intlTelInputUtils;
50
- iti.setNumber("+44 7733 123456");
51
- expect(iti.isPossibleNumber()).toBeNull();
52
- });
53
-
54
- });
55
-
56
- });