intl-tel-input 18.1.0 → 18.1.1
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/.eslintrc +2 -8
- package/.vscode/settings.json +8 -0
- package/CHANGELOG.md +3 -0
- package/Gruntfile.js +0 -2
- package/README.md +14 -25
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput-jquery.js +160 -59
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +160 -59
- package/build/js/intlTelInput.min.js +3 -3
- package/composer.json +1 -1
- package/demo.html +42 -44
- package/demo_rtl.html +21 -23
- package/grunt/template.js +2 -265
- package/package.json +4 -1
- package/src/js/intlTelInput.js +563 -333
- package/examples/css/countrySync.css +0 -10
- package/examples/css/isValidNumber.css +0 -12
- package/examples/css/prism.css +0 -126
- package/examples/gen/country-sync.html +0 -98
- package/examples/gen/default-country-ip.html +0 -62
- package/examples/gen/display-number.html +0 -47
- package/examples/gen/hidden-input.html +0 -54
- package/examples/gen/init-promise.html +0 -66
- package/examples/gen/is-valid-number.html +0 -86
- package/examples/gen/js/countrySync.js +0 -31
- package/examples/gen/js/defaultCountryIp.js +0 -11
- package/examples/gen/js/displayNumber.js +0 -4
- package/examples/gen/js/hiddenInput.js +0 -5
- package/examples/gen/js/initPromise.js +0 -9
- package/examples/gen/js/isValidNumber.js +0 -37
- package/examples/gen/js/modifyCountryData.js +0 -11
- package/examples/gen/js/multipleInstances.js +0 -13
- package/examples/gen/js/nationalMode.js +0 -18
- package/examples/gen/js/onlyCountriesEurope.js +0 -8
- package/examples/gen/modify-country-data.html +0 -52
- package/examples/gen/multiple-instances.html +0 -60
- package/examples/gen/national-mode.html +0 -63
- package/examples/gen/only-countries-europe.html +0 -49
- package/examples/js/countrySync.js.ejs +0 -31
- package/examples/js/defaultCountryIp.js.ejs +0 -11
- package/examples/js/displayNumber.js.ejs +0 -4
- package/examples/js/hiddenInput.js.ejs +0 -5
- package/examples/js/initPromise.js.ejs +0 -9
- package/examples/js/isValidNumber.js.ejs +0 -37
- package/examples/js/modifyCountryData.js.ejs +0 -11
- package/examples/js/multipleInstances.js.ejs +0 -13
- package/examples/js/nationalMode.js.ejs +0 -18
- package/examples/js/onlyCountriesEurope.js.ejs +0 -8
- package/examples/js/prism.js +0 -11
- package/examples/partials/countrySync.html +0 -13
- package/examples/partials/defaultCountryIp.html +0 -5
- package/examples/partials/displayNumber.html +0 -1
- package/examples/partials/hiddenInput.html +0 -4
- package/examples/partials/initPromise.html +0 -8
- package/examples/partials/isValidNumber.html +0 -3
- package/examples/partials/multipleInstances.html +0 -3
- package/examples/partials/nationalMode.html +0 -2
- package/examples/partials/simpleInput.html +0 -1
- package/examples/template.html.ejs +0 -43
package/.eslintrc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "airbnb",
|
|
2
|
+
"extends": ["airbnb", "prettier"],
|
|
3
3
|
"parser": "babel-eslint",
|
|
4
4
|
"env": {
|
|
5
5
|
"browser": true,
|
|
@@ -8,13 +8,7 @@
|
|
|
8
8
|
"arrow-parens": "off",
|
|
9
9
|
"camelcase": "off",
|
|
10
10
|
"class-methods-use-this": "off",
|
|
11
|
-
"
|
|
12
|
-
"arrays": "always-multiline",
|
|
13
|
-
"exports": "always-multiline",
|
|
14
|
-
"functions": "never",
|
|
15
|
-
"imports": "always-multiline",
|
|
16
|
-
"objects": "always-multiline",
|
|
17
|
-
}],
|
|
11
|
+
"curly": ["error", "all"],
|
|
18
12
|
"no-cond-assign": ["error", "except-parens"],
|
|
19
13
|
"no-lonely-if": "off",
|
|
20
14
|
"no-multi-assign": "off",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
|
|
3
|
+
"editor.formatOnPaste": false, // required
|
|
4
|
+
"editor.formatOnType": false, // required
|
|
5
|
+
"editor.formatOnSaveMode": "file", // required to format on save
|
|
6
|
+
"files.autoSave": "onFocusChange", // optional but recommended
|
|
7
|
+
"vs-code-prettier-eslint.prettierLast": "false" // set as "true" to run 'prettier' last not first
|
|
8
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v18.1.1 (2023-04-13)
|
|
4
|
+
- Simplify nationalMode option. Previously, when nationalMode was set to false, the plugin was needlessly creating a worse UX for users who typed a valid national number in 2 situations: (1) it wouldn't update the flag between NANP countries if you typed a different area code (in national format), and (2) isValidNumber would return false for a valid national number.
|
|
5
|
+
|
|
3
6
|
## v18.0.0 (2023-04-07)
|
|
4
7
|
- Remove autoHideDialCode option in favour of new autoInsertDialCode option
|
|
5
8
|
- Allow nationalMode to be used with separateDialCode
|
package/Gruntfile.js
CHANGED
|
@@ -16,8 +16,6 @@ module.exports = function(grunt) {
|
|
|
16
16
|
// just javascript (babel must go before we add the wrapper, to keep it's generated methods inside, so not globals)
|
|
17
17
|
grunt.registerTask('js', ['eslint', 'template:jsAddVersion', 'babel', 'concat', 'uglify', 'replace']);
|
|
18
18
|
|
|
19
|
-
// build examples
|
|
20
|
-
grunt.registerTask('examples', ['template']);
|
|
21
19
|
// Travis CI
|
|
22
20
|
grunt.registerTask('travis', ['jasmine']);
|
|
23
21
|
// bump version number in 3 files, rebuild js to update headers, then commit, tag and push
|
package/README.md
CHANGED
|
@@ -47,12 +47,12 @@ You can view [a live demo](https://intl-tel-input.com) and see some examples of
|
|
|
47
47
|
| :----: | :--: | :----: | :--: | :------------: | :-----------: | :----: |
|
|
48
48
|
| ✓ | ✓ | ✓ | 11 | ✓ | ✓ | ✓ |
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
_Note: In v12.0.0 we dropped support for IE9 and IE10, because they are [no longer supported](https://www.xfive.co/blog/stop-supporting-ie10-ie9-ie8/) by any version of Windows._
|
|
51
51
|
|
|
52
52
|
## Getting Started (Using a bundler e.g. Webpack)
|
|
53
53
|
1. Install with npm: `npm install intl-tel-input --save` or yarn: `yarn add intl-tel-input`
|
|
54
54
|
|
|
55
|
-
2. Import CSS: `import 'intl-tel-input/build/css/intlTelInput.css';`
|
|
55
|
+
2. Import the CSS: `import 'intl-tel-input/build/css/intlTelInput.css';`
|
|
56
56
|
|
|
57
57
|
3. Override the path to flags.png in your CSS
|
|
58
58
|
```css
|
|
@@ -63,7 +63,7 @@ Note: In v12.0.0 we dropped support for IE9 and IE10, because they are no longer
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
4. Import JS and initialise plugin
|
|
66
|
+
4. Import the JS and initialise the plugin on your input element
|
|
67
67
|
```js
|
|
68
68
|
import intlTelInput from 'intl-tel-input';
|
|
69
69
|
|
|
@@ -94,8 +94,6 @@ Note: In v12.0.0 we dropped support for IE9 and IE10, because they are no longer
|
|
|
94
94
|
|
|
95
95
|
4. Add the plugin script and initialise it on your input element
|
|
96
96
|
```html
|
|
97
|
-
<input type="tel" id="phone">
|
|
98
|
-
|
|
99
97
|
<script src="path/to/intlTelInput.js"></script>
|
|
100
98
|
<script>
|
|
101
99
|
var input = document.querySelector("#phone");
|
|
@@ -111,7 +109,9 @@ Note: In v12.0.0 we dropped support for IE9 and IE10, because they are no longer
|
|
|
111
109
|
## Recommended Usage
|
|
112
110
|
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 `separateDialCode` 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.
|
|
113
111
|
|
|
114
|
-
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.
|
|
112
|
+
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 remove the international dial code for you).
|
|
113
|
+
|
|
114
|
+
Finally, make sure you have `<meta charset="utf-8">` in the `<head>` section of your page, else you will get an error as the JS contains some special unicode characters.
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
## Initialisation Options
|
|
@@ -121,9 +121,6 @@ When you initialise the plugin, the first argument is the input element, and the
|
|
|
121
121
|
Type: `Boolean` Default: `true`
|
|
122
122
|
Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected flag is not clickable. Also we display the selected flag on the right instead because it is just a marker of state.
|
|
123
123
|
|
|
124
|
-
**~~autoFormat~~ [REMOVED]**
|
|
125
|
-
Automatically format the number as the user types. Unfortunately this had to be removed for the reasons listed here: [#346 Disable and remove autoFormat feature](https://github.com/jackocnr/intl-tel-input/issues/346).
|
|
126
|
-
|
|
127
124
|
**autoInsertDialCode**
|
|
128
125
|
Type: `Boolean` Default: `false`
|
|
129
126
|
When enabled (requires `nationalMode` to be disabled), the international dial code will be automatically inserted into the input in 3 situations: (A) upon initialisation, and (B) when the user selects a country from the dropdown, and (C) upon calling `setCountry`. Additionally, the plugin will listen for blur/submit events, and if the input only contains a dial code, it will automatically be removed to avoid submitting just that.
|
|
@@ -164,7 +161,7 @@ Format the input value (according to the `nationalMode` option) during initialis
|
|
|
164
161
|
Type: `Function` Default: `null`
|
|
165
162
|
When setting `initialCountry` to `"auto"`, you must use this option to specify a custom function that looks up the user's location, and then calls the success callback with the relevant country code. Also note that when instantiating the plugin, if the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is defined, one of those is returned under the `promise` instance property, so you can do something like `iti.promise.then(callback)` to know when initialisation requests like this have completed.
|
|
166
163
|
|
|
167
|
-
Here is an example using the [ipapi
|
|
164
|
+
Here is an example using the [ipapi](https://ipapi.co/api/?javascript#location-of-clients-ip) service:
|
|
168
165
|
```js
|
|
169
166
|
intlTelInput(input, {
|
|
170
167
|
initialCountry: "auto",
|
|
@@ -184,7 +181,7 @@ Add a hidden input with the given name. Alternatively, if your input name contai
|
|
|
184
181
|
|
|
185
182
|
**initialCountry**
|
|
186
183
|
Type: `String` Default: `""`
|
|
187
|
-
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/
|
|
184
|
+
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.
|
|
188
185
|
|
|
189
186
|
If you leave `initialCountry` blank, it will default to the first country in the list.
|
|
190
187
|
|
|
@@ -198,11 +195,11 @@ Allows to translate the countries by its given iso code e.g.:
|
|
|
198
195
|
|
|
199
196
|
**nationalMode**
|
|
200
197
|
Type: `Boolean` Default: `true`
|
|
201
|
-
|
|
198
|
+
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.
|
|
202
199
|
|
|
203
200
|
**onlyCountries**
|
|
204
201
|
Type: `Array` Default: `undefined`
|
|
205
|
-
In the dropdown, display only the countries you specify - [see example](https://intl-tel-input.com/
|
|
202
|
+
In the dropdown, display only the countries you specify - [see example](https://intl-tel-input.com/examples/only-countries.html).
|
|
206
203
|
|
|
207
204
|
**placeholderNumberType**
|
|
208
205
|
Type: `String` Default: `"MOBILE"`
|
|
@@ -212,9 +209,6 @@ Specify [one of the keys](https://github.com/jackocnr/intl-tel-input/blob/master
|
|
|
212
209
|
Type: `Array` Default: `["us", "gb"]`
|
|
213
210
|
Specify the countries to appear at the top of the list.
|
|
214
211
|
|
|
215
|
-
**~~preventInvalidNumbers~~ [REMOVED]**
|
|
216
|
-
Prevent the user from entering invalid characters. Unfortunately this had to be removed for the reasons listed here: [#79 Limit Input Characters to Formatted String Length](https://github.com/jackocnr/intl-tel-input/issues/79#issuecomment-121799307).
|
|
217
|
-
|
|
218
212
|
**separateDialCode**
|
|
219
213
|
Type: `Boolean` Default: `false`
|
|
220
214
|
Display the country dial code next to the selected flag.
|
|
@@ -295,7 +289,7 @@ if (error === intlTelInputUtils.validationError.TOO_SHORT) {
|
|
|
295
289
|
```
|
|
296
290
|
|
|
297
291
|
**isValidNumber**
|
|
298
|
-
Validate the current number - [see example](https://intl-tel-input.com/
|
|
292
|
+
Validate the current number - [see example](https://intl-tel-input.com/examples/validation.html). If validation fails, you can use `getValidationError` to get more information. Requires the `utilsScript` option. Also see `getNumberType` if you want to make sure the user enters a certain type of number e.g. a mobile number.
|
|
299
293
|
```js
|
|
300
294
|
var isValid = iti.isValidNumber();
|
|
301
295
|
```
|
|
@@ -308,7 +302,7 @@ iti.setCountry("gb");
|
|
|
308
302
|
```
|
|
309
303
|
|
|
310
304
|
**setNumber**
|
|
311
|
-
Insert a number, and update the selected flag accordingly. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number according to the `nationalMode` option._
|
|
305
|
+
Insert a number, and update the selected flag accordingly. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number to either national or international format according to the `nationalMode` option._
|
|
312
306
|
```js
|
|
313
307
|
iti.setNumber("+447733123456");
|
|
314
308
|
```
|
|
@@ -323,7 +317,7 @@ iti.setPlaceholderNumberType("FIXED_LINE");
|
|
|
323
317
|
## Static Methods
|
|
324
318
|
|
|
325
319
|
**getCountryData**
|
|
326
|
-
Get all of the plugin's country data - either to re-use elsewhere e.g. to populate a country dropdown - [see example](https://intl-tel-input.com/
|
|
320
|
+
Get all of the plugin's country data - either to re-use elsewhere e.g. to populate a country dropdown - [see example](https://intl-tel-input.com/examples/country-sync.html), or to modify - [see example](https://intl-tel-input.com/examples/modify-country-data.html). Note that any modifications must be done before initialising the plugin.
|
|
327
321
|
```js
|
|
328
322
|
var countryData = window.intlTelInputGlobals.getCountryData();
|
|
329
323
|
```
|
|
@@ -350,10 +344,6 @@ An alternative to the `utilsScript` option, this method lets you manually load t
|
|
|
350
344
|
window.intlTelInputGlobals.loadUtils("build/js/utils.js");
|
|
351
345
|
```
|
|
352
346
|
|
|
353
|
-
**~~setCountryData~~ [REMOVED]**
|
|
354
|
-
Set the plugin's country data. This method was removed because it makes much more sense to just use `getCountryData` and then modify that ([see example](https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/modify-country-data.html)) instead of having to generate the whole thing yourself - the country data has become increasingly complicated and for each country we now have five properties: the name, [iso2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), international dial code, priority (in case two countries have the same international dial code), and finally a list of area codes used in that country - see [data.js](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/data.js#L36) for more info.
|
|
355
|
-
|
|
356
|
-
|
|
357
347
|
## Events
|
|
358
348
|
You can listen for the following events on the input.
|
|
359
349
|
|
|
@@ -364,7 +354,7 @@ input.addEventListener("countrychange", function() {
|
|
|
364
354
|
// do something with iti.getSelectedCountryData()
|
|
365
355
|
});
|
|
366
356
|
```
|
|
367
|
-
See an example here: [Country sync](https://intl-tel-input.com/
|
|
357
|
+
See an example here: [Country sync](https://intl-tel-input.com/examples/country-sync.html)
|
|
368
358
|
|
|
369
359
|
**open:countrydropdown**
|
|
370
360
|
This is triggered when the user opens the dropdown.
|
|
@@ -440,7 +430,6 @@ See the [contributing guide](https://github.com/jackocnr/intl-tel-input/blob/mas
|
|
|
440
430
|
|
|
441
431
|
## Links
|
|
442
432
|
* List of [integrations with intl-tel-input](https://github.com/jackocnr/intl-tel-input/wiki/Integrations)
|
|
443
|
-
* Android native port: [IntlPhoneInput](https://github.com/Rimoto/IntlPhoneInput)
|
|
444
433
|
* Typescript type definitions are available in the [DefinitelyTyped repo](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/intl-tel-input/index.d.ts) (more info [here](https://github.com/jackocnr/intl-tel-input/issues/433#issuecomment-228517623))
|
|
445
434
|
|
|
446
435
|
<img width="200" src="https://www.browserstack.com/images/layout/browserstack-logo-600x315.png" /><br />
|
package/build/js/data.js
CHANGED
package/build/js/data.min.js
CHANGED