intl-tel-input 18.5.3 → 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.
- package/README.md +42 -28
- package/build/css/demo.css +1 -1
- package/build/css/intlTelInput.css +28 -20
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput-jquery.js +158 -151
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +158 -151
- package/build/js/intlTelInput.min.js +3 -3
- package/composer.json +1 -1
- package/demo.html +5 -5
- package/grunt/replace.js +1 -7
- package/package.json +1 -1
- package/spec.html +6 -4
- package/src/css/demo.scss +1 -1
- package/src/css/intlTelInput.scss +41 -30
- package/src/js/intlTelInput.js +76 -125
- package/src/spec/helpers/helpers.js +23 -10
- package/src/spec/tests/core/countrychangeEvent.js +1 -1
- package/src/spec/tests/core/dropdownShortcuts.js +3 -2
- package/src/spec/tests/core/initialValues.js +2 -3
- package/src/spec/tests/methods/getSelectedCountryData.js +1 -1
- package/src/spec/tests/methods/isValidNumber.js +15 -32
- package/src/spec/tests/methods/isValidNumberPrecise.js +73 -0
- package/src/spec/tests/methods/setCountry.js +4 -4
- package/src/spec/tests/options/allowDropdown.js +3 -3
- package/src/spec/tests/options/autoInsertDialCode.js +1 -3
- package/src/spec/tests/options/autoPlaceholder.js +5 -5
- package/src/spec/tests/options/{customContainer.js → containerClass.js} +3 -3
- package/src/spec/tests/options/countrySearch.js +63 -0
- package/src/spec/tests/options/customPlaceholder.js +1 -1
- package/src/spec/tests/options/preferredCountries.js +3 -1
- package/src/spec/tests/options/{separateDialCode.js → showSelectedDialCode.js} +7 -7
- package/src/spec/tests/methods/isPossibleNumber.js +0 -56
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ _Note: We have now dropped support for all versions of Internet Explorer because
|
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
## Recommended Usage
|
|
122
|
-
We highly recommend you (lazy) load the included utils.js using the `utilsScript` option. Then the plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when `nationalMode` or `
|
|
122
|
+
We highly recommend you (lazy) load the included utils.js using the `utilsScript` option. Then the plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when `nationalMode` or `showSelectedDialCode` is enabled. We recommend you get, store, and set numbers exclusively in this format for simplicity - then you don't have to deal with handling the country code separately, as full international numbers include the country code information.
|
|
123
123
|
|
|
124
124
|
You can always get the full international number (including country code) using `getNumber`, then you only have to store that one string in your database (you don't have to store the country separately), and then the next time you initialise the plugin with that number it will automatically set the country and format it according to the options you specify (e.g. when using `nationalMode` it will automatically display the number in national format, removing the international dial code).
|
|
125
125
|
|
|
@@ -141,14 +141,14 @@ When enabled (requires `nationalMode` to be disabled), the international dial co
|
|
|
141
141
|
Type: `String` Default: `"polite"`
|
|
142
142
|
Set the input's placeholder to an example number for the selected country, and update it if the country changes. You can specify the number type using the `placeholderNumberType` option. By default it is set to `"polite"`, which means it will only set the placeholder if the input doesn't already have one. You can also set it to `"aggressive"`, which will replace any existing placeholder, or `"off"`. Requires the `utilsScript` option.
|
|
143
143
|
|
|
144
|
+
**containerClass**
|
|
145
|
+
Type: `String` Default: `""`
|
|
146
|
+
Additional classes to add to the (injected) wrapper `<div>`.
|
|
147
|
+
|
|
144
148
|
**countrySearch**
|
|
145
149
|
Type: `Boolean` Default: `false`
|
|
146
150
|
Add a search input to the top of the dropdown, so users can filter the displayed countries.
|
|
147
151
|
|
|
148
|
-
**customContainer**
|
|
149
|
-
Type: `String` Default: `""`
|
|
150
|
-
Additional classes to add to the parent div.
|
|
151
|
-
|
|
152
152
|
**customPlaceholder**
|
|
153
153
|
Type: `Function` Default: `null`
|
|
154
154
|
Change the placeholder generated by autoPlaceholder. Must return a string.
|
|
@@ -191,27 +191,30 @@ intlTelInput(input, {
|
|
|
191
191
|
.then(function(data) { callback(data.country_code); })
|
|
192
192
|
.catch(function() { callback("us"); });
|
|
193
193
|
}
|
|
194
|
-
})
|
|
194
|
+
});
|
|
195
195
|
```
|
|
196
196
|
_Note that the callback must still be called in the event of an error, hence the use of `catch()` in this example. Tip: store the result in a cookie to avoid repeat lookups!_
|
|
197
197
|
|
|
198
198
|
**hiddenInput**
|
|
199
|
-
Type: `
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
**initialCountry**
|
|
203
|
-
Type: `String` Default: `""`
|
|
204
|
-
Set the initial country selection by specifying its country code. You can also set it to `"auto"`, which will lookup the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note that the `"auto"` option will not update the country selection if the input already contains a number.
|
|
199
|
+
Type: `Function` Default: `null`
|
|
200
|
+
Creates a hidden input which gets populated with the full international number on submit. You must provide a function (which receives the main telephone input name as an argument, in case that's useful) and it must return the name to use for the hidden input. This is a quick way for people using non-Ajax forms to get the full international number, even when `nationalMode` is enabled. Avoid this option when using Ajax forms and instead just call `getNumber` to get the full international number to send in the request. _Note: requires the input to be inside a `<form>` element, as this feature works by listening for the `submit` event on the closest form element. Also note that since this uses `getNumber` internally, firstly it requires the `utilsScript` option, and secondly it expects a valid number and so will only work correctly if you have used `isValidNumber` to validate the number before allowing the form submit to go through._
|
|
205
201
|
|
|
206
|
-
|
|
202
|
+
```js
|
|
203
|
+
intlTelInput(input, {
|
|
204
|
+
hiddenInput: function(telInputName) {
|
|
205
|
+
return "phone_full"
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
```
|
|
207
209
|
|
|
208
|
-
**
|
|
210
|
+
**i18n**
|
|
209
211
|
Type: `Object` Default: `{}`
|
|
210
|
-
Allow localisation of country names.
|
|
212
|
+
Allow localisation/customisation of country names and other plugin text. To localise a country name, the key should be the iso2 country code, and the value should be the localised country name. [See example](https://intl-tel-input.com/examples/localise-countries.html).
|
|
211
213
|
|
|
212
214
|
```js
|
|
213
|
-
|
|
214
|
-
{
|
|
215
|
+
intlTelInput(input, {
|
|
216
|
+
i18n: {
|
|
217
|
+
// Country names
|
|
215
218
|
fr: "Frankreich",
|
|
216
219
|
de: "Deutschland",
|
|
217
220
|
es: "Spanien",
|
|
@@ -220,9 +223,20 @@ Allow localisation of country names. For each country, the key should be the iso
|
|
|
220
223
|
nl: "Niederlande",
|
|
221
224
|
at: "Österreich",
|
|
222
225
|
dk: "Dänemark",
|
|
226
|
+
// Other plugin text
|
|
227
|
+
selectedCountryAriaLabel: 'Ausgewähltes Land',
|
|
228
|
+
countryListAriaLabel: 'Liste der Länder',
|
|
229
|
+
searchPlaceholder: 'Suchen',
|
|
223
230
|
}
|
|
231
|
+
});
|
|
224
232
|
```
|
|
225
233
|
|
|
234
|
+
**initialCountry**
|
|
235
|
+
Type: `String` Default: `""`
|
|
236
|
+
Set the initial country selection by specifying its country code. You can also set it to `"auto"`, which will lookup the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note that the `"auto"` option will not update the country selection if the input already contains a number.
|
|
237
|
+
|
|
238
|
+
If you leave `initialCountry` blank, it will default to the first country in the list.
|
|
239
|
+
|
|
226
240
|
**nationalMode**
|
|
227
241
|
Type: `Boolean` Default: `true`
|
|
228
242
|
Format numbers in the national format, rather than the international format. This applies to placeholder numbers, and when displaying user's existing numbers. Note that it's fine for user's to type their numbers in national format - as long as they have selected the right country, you can use `getNumber` to extract a full international number - [see example](https://intl-tel-input.com/examples/national-mode.html). It is recommended to leave this option enabled, to encourage users to enter their numbers in national format as this is usually more familiar to them and so it creates a better user experience.
|
|
@@ -239,16 +253,16 @@ Specify [one of the keys](https://github.com/jackocnr/intl-tel-input/blob/master
|
|
|
239
253
|
Type: `Array` Default: `["us", "gb"]`
|
|
240
254
|
Specify the countries to appear at the top of the list.
|
|
241
255
|
|
|
242
|
-
**
|
|
256
|
+
**showFlags**
|
|
257
|
+
Type: `Boolean` Default: `true`
|
|
258
|
+
Set this to false to hide the flags e.g. for political reasons. Must be used in combination with `showSelectedDialCode` option, or with setting `allowDropdown` to `false`.
|
|
259
|
+
|
|
260
|
+
**showSelectedDialCode**
|
|
243
261
|
Type: `Boolean` Default: `false`
|
|
244
262
|
Display the country dial code next to the selected flag.
|
|
245
263
|
|
|
246
264
|
<img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separateDialCode.png" width="257px" height="46px">
|
|
247
265
|
|
|
248
|
-
**showFlags**
|
|
249
|
-
Type: `Boolean` Default: `true`
|
|
250
|
-
Set this to false to hide the flags e.g. for political reasons. Must be used in combination with `separateDialCode` option, or with setting `allowDropdown` to `false`.
|
|
251
|
-
|
|
252
266
|
**useFullscreenPopup**
|
|
253
267
|
Type: `Boolean` Default: `true on mobile devices, false otherwise`
|
|
254
268
|
Control when the country list appears as a fullscreen popup vs a dropdown. By default, it will appear as a fullscreen popup on mobile devices (based on user-agent and screen width), and as a dropdown on larger devices/screens.
|
|
@@ -322,17 +336,17 @@ if (error === intlTelInputUtils.validationError.TOO_SHORT) {
|
|
|
322
336
|
}
|
|
323
337
|
```
|
|
324
338
|
|
|
325
|
-
**
|
|
326
|
-
Check if the current number is
|
|
339
|
+
**isValidNumber**
|
|
340
|
+
Check if the current number is valid based on its length - [see example](https://intl-tel-input.com/examples/validation-practical.html), which should be sufficient for most use cases. See `isValidNumberPrecise` for more precise validation, but the advantage of `isValidNumber` is that it is much more future-proof as while countries around the world regularly update their number rules, they very rarely change their number lengths. If it returns false, you can use `getValidationError` to get more information. Requires the `utilsScript` option.
|
|
327
341
|
```js
|
|
328
|
-
const isPossible = iti.
|
|
342
|
+
const isPossible = iti.isValidNumber();
|
|
329
343
|
```
|
|
330
344
|
Returns: `true`/`false`
|
|
331
345
|
|
|
332
|
-
**
|
|
333
|
-
Check if the current number is valid - [see example](https://intl-tel-input.com/examples/validation.html).
|
|
346
|
+
**isValidNumberPrecise**
|
|
347
|
+
Check if the current number is valid using precise matching rules for each country/area code etc - [see example](https://intl-tel-input.com/examples/validation.html). Note that these rules change each month for various countries around the world, so you need to be careful to keep the plugin up-to-date else you will start rejecting valid numbers. For a simpler and more future-proof form of validation, see `isValidNumber` above. If validation fails, you can use `getValidationError` to get more information. Requires the `utilsScript` option.
|
|
334
348
|
```js
|
|
335
|
-
const isValid = iti.
|
|
349
|
+
const isValid = iti.isValidNumberPrecise();
|
|
336
350
|
```
|
|
337
351
|
Returns: `true`/`false`
|
|
338
352
|
|
package/build/css/demo.css
CHANGED
|
@@ -53,28 +53,36 @@
|
|
|
53
53
|
border-bottom: 4px solid #555;
|
|
54
54
|
}
|
|
55
55
|
.iti__dropdown-content {
|
|
56
|
+
border-radius: 3px;
|
|
57
|
+
background-color: white;
|
|
58
|
+
}
|
|
59
|
+
.iti--inline-dropdown .iti__dropdown-content {
|
|
56
60
|
position: absolute;
|
|
57
61
|
z-index: 2;
|
|
62
|
+
margin-top: 3px;
|
|
58
63
|
margin-left: -1px;
|
|
59
|
-
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
|
|
60
|
-
background-color: white;
|
|
61
64
|
border: 1px solid #ccc;
|
|
62
|
-
|
|
63
|
-
overflow-y: scroll;
|
|
64
|
-
-webkit-overflow-scrolling: touch;
|
|
65
|
+
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
|
|
65
66
|
}
|
|
66
67
|
.iti__dropdown-content--dropup {
|
|
67
68
|
bottom: 100%;
|
|
68
|
-
margin-bottom:
|
|
69
|
+
margin-bottom: 3px;
|
|
69
70
|
}
|
|
70
71
|
.iti__search-input {
|
|
71
72
|
width: 100%;
|
|
72
73
|
border-width: 0;
|
|
74
|
+
border-radius: 3px;
|
|
75
|
+
}
|
|
76
|
+
.iti__search-input + .iti__country-list {
|
|
77
|
+
border-top: 1px solid #ccc;
|
|
73
78
|
}
|
|
74
79
|
.iti__country-list {
|
|
75
80
|
list-style: none;
|
|
76
81
|
padding: 0;
|
|
77
82
|
margin: 0;
|
|
83
|
+
max-height: 185px;
|
|
84
|
+
overflow-y: scroll;
|
|
85
|
+
-webkit-overflow-scrolling: touch;
|
|
78
86
|
}
|
|
79
87
|
.iti--flexible-dropdown-width .iti__country-list {
|
|
80
88
|
white-space: nowrap;
|
|
@@ -96,7 +104,7 @@
|
|
|
96
104
|
.iti__country {
|
|
97
105
|
display: flex;
|
|
98
106
|
align-items: center;
|
|
99
|
-
padding:
|
|
107
|
+
padding: 8px 8px;
|
|
100
108
|
outline: none;
|
|
101
109
|
}
|
|
102
110
|
.iti__dial-code {
|
|
@@ -106,35 +114,35 @@
|
|
|
106
114
|
background-color: rgba(0, 0, 0, 0.05);
|
|
107
115
|
}
|
|
108
116
|
.iti__flag-box, .iti__country-name {
|
|
109
|
-
margin-right:
|
|
117
|
+
margin-right: 8px;
|
|
110
118
|
}
|
|
111
119
|
[dir=rtl] .iti__flag-box, [dir=rtl] .iti__country-name {
|
|
112
120
|
margin-right: 0;
|
|
113
|
-
margin-left:
|
|
121
|
+
margin-left: 8px;
|
|
114
122
|
}
|
|
115
123
|
.iti--allow-dropdown input.iti__tel-input,
|
|
116
124
|
.iti--allow-dropdown input.iti__tel-input[type=text],
|
|
117
|
-
.iti--allow-dropdown input.iti__tel-input[type=tel], .iti--
|
|
118
|
-
.iti--
|
|
119
|
-
.iti--
|
|
125
|
+
.iti--allow-dropdown input.iti__tel-input[type=tel], .iti--show-selected-dial-code input.iti__tel-input,
|
|
126
|
+
.iti--show-selected-dial-code input.iti__tel-input[type=text],
|
|
127
|
+
.iti--show-selected-dial-code input.iti__tel-input[type=tel] {
|
|
120
128
|
padding-right: 6px;
|
|
121
129
|
padding-left: 52px;
|
|
122
130
|
margin-left: 0;
|
|
123
131
|
}
|
|
124
132
|
[dir=rtl] .iti--allow-dropdown input.iti__tel-input,
|
|
125
133
|
[dir=rtl] .iti--allow-dropdown input.iti__tel-input[type=text],
|
|
126
|
-
[dir=rtl] .iti--allow-dropdown input.iti__tel-input[type=tel], [dir=rtl] .iti--
|
|
127
|
-
[dir=rtl] .iti--
|
|
128
|
-
[dir=rtl] .iti--
|
|
134
|
+
[dir=rtl] .iti--allow-dropdown input.iti__tel-input[type=tel], [dir=rtl] .iti--show-selected-dial-code input.iti__tel-input,
|
|
135
|
+
[dir=rtl] .iti--show-selected-dial-code input.iti__tel-input[type=text],
|
|
136
|
+
[dir=rtl] .iti--show-selected-dial-code input.iti__tel-input[type=tel] {
|
|
129
137
|
padding-right: 52px;
|
|
130
138
|
padding-left: 6px;
|
|
131
139
|
margin-right: 0;
|
|
132
140
|
}
|
|
133
|
-
.iti--allow-dropdown .iti__flag-container, .iti--
|
|
141
|
+
.iti--allow-dropdown .iti__flag-container, .iti--show-selected-dial-code .iti__flag-container {
|
|
134
142
|
right: auto;
|
|
135
143
|
left: 0;
|
|
136
144
|
}
|
|
137
|
-
[dir=rtl] .iti--allow-dropdown .iti__flag-container, [dir=rtl] .iti--
|
|
145
|
+
[dir=rtl] .iti--allow-dropdown .iti__flag-container, [dir=rtl] .iti--show-selected-dial-code .iti__flag-container {
|
|
138
146
|
right: 0;
|
|
139
147
|
left: auto;
|
|
140
148
|
}
|
|
@@ -152,13 +160,13 @@
|
|
|
152
160
|
.iti--allow-dropdown .iti__flag-container:has(+ input[readonly]):hover .iti__selected-flag {
|
|
153
161
|
background-color: transparent;
|
|
154
162
|
}
|
|
155
|
-
.iti--
|
|
163
|
+
.iti--show-selected-dial-code .iti__selected-flag {
|
|
156
164
|
background-color: rgba(0, 0, 0, 0.05);
|
|
157
165
|
}
|
|
158
|
-
.iti--
|
|
166
|
+
.iti--show-selected-dial-code.iti--show-flags .iti__selected-dial-code {
|
|
159
167
|
margin-left: 6px;
|
|
160
168
|
}
|
|
161
|
-
[dir=rtl] .iti--
|
|
169
|
+
[dir=rtl] .iti--show-selected-dial-code.iti--show-flags .iti__selected-dial-code {
|
|
162
170
|
margin-left: 0;
|
|
163
171
|
margin-right: 6px;
|
|
164
172
|
}
|
package/build/js/data.js
CHANGED
package/build/js/data.min.js
CHANGED