intl-tel-input 24.1.3 → 24.2.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/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/typescript.webp" alt="Typescript logo" width="16px" /> NEWS: we now have our own Typescript type definitions, so no need to use `@types/intl-tel-input` anymore!
6
6
 
7
- 🗣️ NEWS: we now provide [translations](https://github.com/jackocnr/intl-tel-input/tree/master/build/js/i18n) in over 30 languages! [See them in action](https://intl-tel-input.com/examples/localise-countries.html).
7
+ 🗣️ NEWS: we now provide [translations](https://github.com/jackocnr/intl-tel-input/tree/master/build/js/i18n) in over 30 languages! [See them in action](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--i18n).
8
8
 
9
9
  International Telephone Input is a JavaScript plugin for entering and validating international telephone numbers. It takes a regular input field, adds a searchable country dropdown, auto-detects the user's country, displays a relevant placeholder number, formats the number as you type, and provides comprehensive validation methods.
10
10
 
11
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-search2.png" alt="Screenshot" width="237px" height="280px" />
11
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla2.png" alt="Screenshot" width="265px" height="273px" />
12
12
 
13
13
  If you find the plugin helpful, please consider [supporting the project](https://github.com/sponsors/jackocnr).
14
14
 
@@ -45,12 +45,12 @@ You can view [a live demo](https://intl-tel-input.com) and see some examples of
45
45
  ## Mobile
46
46
  By default, on mobile devices we show a fullscreen popup instead of the inline dropdown, to make better use of the limited screen space. This is similar to how a native `<select>` element works. You can control this behaviour with the `useFullscreenPopup` option. The popup can be closed by either selecting a country from the list or by tapping on the grey area at the sides. [See example](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--usefullscreenpopup) (using the React component).
47
47
 
48
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/mobile.png" alt="Mobile screenshot" width="270px" style="max-width: 100%" />
48
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/mobile2.png" alt="Mobile screenshot" width="270px" height="512px" />
49
49
 
50
50
  ## Features
51
51
  * Automatically select the user's current country using an IP lookup
52
52
  * Automatically set the input placeholder to an example number for the selected country
53
- * Navigate the country dropdown by typing a country's name, or using up/down keys
53
+ * Navigate the country dropdown by typing a country's name, or using the up/down keys
54
54
  * Automatically format the number as the user types
55
55
  * Optionally only allow numeric characters and cap the number at the maximum valid length
56
56
  * The user types their national number and the plugin gives you the full standardised international number
@@ -73,16 +73,16 @@ _Note: We have now dropped support for all versions of Internet Explorer because
73
73
  ## Getting Started (Using a CDN)
74
74
  1. Add the CSS
75
75
  ```html
76
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@24.1.3/build/css/intlTelInput.css">
76
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@24.2.1/build/css/intlTelInput.css">
77
77
  ```
78
78
 
79
79
  2. Add the plugin script and initialise it on your input element
80
80
  ```html
81
- <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@24.1.3/build/js/intlTelInput.min.js"></script>
81
+ <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@24.2.1/build/js/intlTelInput.min.js"></script>
82
82
  <script>
83
83
  const input = document.querySelector("#phone");
84
84
  window.intlTelInput(input, {
85
- utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@24.1.3/build/js/utils.js",
85
+ utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@24.2.1/build/js/utils.js",
86
86
  });
87
87
  </script>
88
88
  ```
@@ -159,7 +159,7 @@ Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, a
159
159
 
160
160
  **autoPlaceholder**
161
161
  Type: `String` Default: `"polite"`
162
- 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 [utils script to be loaded](#loading-the-utilities-script).
162
+ 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 [utils script to be loaded](#loading-the-utilities-script).
163
163
 
164
164
  **containerClass**
165
165
  Type: `String` Default: `""`
@@ -167,7 +167,7 @@ Additional classes to add to the (injected) wrapper `<div>`.
167
167
 
168
168
  **countryOrder**
169
169
  Type: `Array` Default: `null`
170
- Specify the ordering for the country list with an array of iso2 country codes. Any ommitted countries will appear after those specified e.g. setting `countryOrder` to `["jp", "kr"]` will result in the list: Japan, South Korea, Afghanistan, Albanbia, Algeria etc...
170
+ Specify the ordering for the country list with an array of iso2 country codes. Any omitted countries will appear after those specified e.g. setting `countryOrder` to `["jp", "kr"]` will result in the list: Japan, South Korea, Afghanistan, Albania, Algeria etc...
171
171
 
172
172
  **countrySearch**
173
173
  Type: `Boolean` Default: `true`
@@ -240,7 +240,7 @@ intlTelInput(input, {
240
240
  });
241
241
  ```
242
242
 
243
- Which will generate the following (hidden) elements, which will be automatically populated on submit:
243
+ This will generate the following (hidden) elements, which will be automatically populated on submit:
244
244
 
245
245
  ```html
246
246
  <input type="hidden" name="phone_full">
@@ -249,15 +249,17 @@ Which will generate the following (hidden) elements, which will be automatically
249
249
 
250
250
  **i18n**
251
251
  Type: `Object` Default: `{}`
252
- Allow localisation/customisation of the 200+ country names, as well as other user interface text (e.g. the country search input placeholder text). The easiest way to do this is to simply import one of the [provided translation modules](https://github.com/jackocnr/intl-tel-input/tree/master/build/js/i18n) and set `i18n` to that (see option 1 below). You can also override one or more individual keys this way if you want (see option 1 below). Alternatively, you can provide your own custom translations (see option 2 below). If providing your own, you will need to specify all the country names (which can be copied from the country-list project e.g. here are the [country names in French](https://github.com/umpirsky/country-list/blob/master/data/fr/country.json)), as well as a few UI strings (listed below). [See example](https://intl-tel-input.com/examples/localise-countries.html).
252
+ Allow localisation/customisation of the 200+ country names, as well as other user interface text (e.g. the placeholder text for the country search input). The easiest way to do this is to simply import one of the [provided translation modules](https://github.com/jackocnr/intl-tel-input/tree/master/build/js/i18n) and set `i18n` to that value (see option 1 below). You can also override one or more individual keys this way (see option 1 below). Alternatively, you can provide your own custom translations (see option 2 below). If providing your own, you will need to specify all the country names (which can be copied from the country-list project e.g. here are the [country names in French](https://github.com/umpirsky/country-list/blob/master/data/fr/country.json)), as well as a few UI strings (listed below). [See example](https://intl-tel-input.com/examples/localise-countries.html).
253
253
 
254
254
  If we don't currently support a language you need, it's easy to [contribute this](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md#adding-a-new-translation) yourself - you only need to provide a handful of UI translation strings, as we automatically pull in the country names from the country-list project.
255
255
 
256
+ Option 1: import one of the provided translation modules
256
257
  ```js
257
- // OPTION 1: import one of the provided translation modules
258
258
  import { fr } from "intl-tel-input/i18n";
259
259
 
260
- intlTelInput(input, { i18n: fr });
260
+ intlTelInput(input, {
261
+ i18n: fr,
262
+ });
261
263
 
262
264
  // or to override one or more keys, you could do something like this
263
265
  intlTelInput(input, {
@@ -266,12 +268,13 @@ intlTelInput(input, {
266
268
  searchPlaceholder: "Recherche de pays",
267
269
  },
268
270
  });
271
+ ```
269
272
 
270
-
271
- // OPTION 2: define your own custom translations
273
+ Option 2: define your own custom translations
274
+ ```js
272
275
  intlTelInput(input, {
273
276
  i18n: {
274
- // Country names - see full list in src/js/intl-tel-input/i18n/en/countries.ts
277
+ // Country names - see the full list in src/js/intl-tel-input/i18n/en/countries.ts
275
278
  af: "Afghanistan",
276
279
  al: "Albania",
277
280
  dz: "Algeria",
@@ -298,11 +301,11 @@ intlTelInput(input, {
298
301
 
299
302
  **initialCountry**
300
303
  Type: `String` Default: `""`
301
- Set the initial country selection by specifying its country code e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user autofills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up 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 however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code.
304
+ Set the initial country selection by specifying its country code e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user auto-fills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up 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 however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code.
302
305
 
303
306
  **nationalMode**
304
307
  Type: `Boolean` Default: `true`
305
- 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.
308
+ Format numbers in the national format, rather than the international format. This applies to placeholder numbers, and when displaying users' existing numbers. Note that it's fine for users 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.
306
309
 
307
310
  **onlyCountries**
308
311
  Type: `Array` Default: `[]`
@@ -314,17 +317,17 @@ Specify [one of the keys](https://github.com/jackocnr/intl-tel-input/blob/master
314
317
 
315
318
  **showFlags**
316
319
  Type: `Boolean` Default: `true`
317
- Set this to false to hide the flags e.g. for political reasons. Instead it will show a generic globe icon. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--showflags) (using the React component).
320
+ Set this to false to hide the flags e.g. for political reasons. Instead, it will show a generic globe icon. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--showflags) (using the React component).
318
321
 
319
322
  **separateDialCode**
320
323
  Type: `Boolean` Default: `false`
321
- Display the selected country dial code next to the input, so it looks like it's part of the typed number, except it is uneditable. When enabled, typing a plus in the telephone input will open the country dropdown and enter the plus in the search input instead, to force the user to select a country from the list rather than typing their dial code in the telephone input. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--separatedialcode) (using the React component).
324
+ Display the selected country's international dial code next to the input, so it looks like it's part of the typed number. Since the user cannot edit the displayed dial code, they may try to type a new one - in this case, to avoid having two dial codes next to each other, we automatically open the country dropdown and put the new dial code in the search input instead. So if they type +54, then Argentina will be highlighted in the dropdown and they can simply press Enter to select it, updating the displayed dial code. For this reason, we force `allowDropdown` to `true`. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--separatedialcode) (using the React component).
322
325
 
323
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separate-dial-code3.png" width="234px" height="49px" alt="Separate Dial Code">
326
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separate-dial-code4.png" width="267px" height="51px" alt="Separate Dial Code">
324
327
 
325
328
  **strictMode**
326
329
  Type: `Boolean` Default: `false`
327
- As the user types in the input, ignore any irrelevant characters. Basically, the user can only enter numeric characters, and an optional plus at the beginning. Cap the length at the maximum valid number length (this respects `validationNumberType`). Requires the [utils script to be loaded](#loading-the-utilities-script). [See example](https://intl-tel-input.com/examples/strict-mode.html).
330
+ As the user types in the input, ignore any irrelevant characters. The user can only enter numeric characters and an optional plus at the beginning. Cap the length at the maximum valid number length (this respects `validationNumberType`). Requires the [utils script to be loaded](#loading-the-utilities-script). [See example](https://intl-tel-input.com/examples/strict-mode.html).
328
331
 
329
332
  **useFullscreenPopup**
330
333
  Type: `Boolean` Default: `true on mobile devices, false otherwise`
@@ -332,7 +335,7 @@ Control when the country list appears as a fullscreen popup vs an inline dropdow
332
335
 
333
336
  **utilsScript**
334
337
  Type: `String` Default: `""` Example: `"/build/js/utils.js"`
335
- This is one way to (lazy) load the included utils.js (to enable formatting/validation etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options. You will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.1.3/build/js/utils.js"`. The script is loaded via a [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) statement, which means the URL cannot be relative - it must be absolute. The script is only fetched when you initialise the plugin, and additionally, only when the page has finished loading (on the window load event) to prevent blocking (the script is ~260KB). When instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object 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 finished. See [Utilities Script](#utilities-script) for more information.
338
+ This is one way to (lazy) load the included utils.js (to enable formatting/validation etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options. You will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.2.1/build/js/utils.js"`. The script is loaded via a [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) statement, which means the URL cannot be relative - it must be absolute. The script is only fetched when you initialise the plugin, and additionally, only when the page has finished loading (on the window load event) to prevent blocking (the script is ~260KB). When instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object 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 finished. See [Utilities Script](#utilities-script) for more information.
336
339
 
337
340
  **validationNumberType**
338
341
  Type: `String` Default: `"MOBILE"`
@@ -438,7 +441,7 @@ iti.setPlaceholderNumberType("FIXED_LINE");
438
441
  ```
439
442
 
440
443
  **setDisabled**
441
- Updates the disabled attribute of both the telephone input and selected country button. Accepts a boolean value. _Note: we recommend using this instead of updating the disabled attribute of the input directly._
444
+ Updates the disabled attribute of both the telephone input and the selected country button. Accepts a boolean value. _Note: we recommend using this instead of updating the disabled attribute of the input directly._
442
445
  ```js
443
446
  iti.setDisabled(true);
444
447
  ```
@@ -474,7 +477,7 @@ intlTelInput.loadUtils("/build/js/utils.js");
474
477
  ```
475
478
 
476
479
  ## Events
477
- You can listen for the following events on the input.
480
+ You can listen for the following events triggered on the input element.
478
481
 
479
482
  **countrychange**
480
483
  This is triggered when the selected country is updated e.g. if the user selects a country from the dropdown, or they type a different dial code into the input, or you call `setCountry` etc.
@@ -529,7 +532,7 @@ NOTE: this assumes you already have your own dark mode styling in place for gene
529
532
  ```
530
533
 
531
534
  Example:
532
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/dark-mode.png" alt="Screenshot" width="269px" height="284px" />
535
+ <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/dark-mode2.png" alt="Screenshot" width="264px" height="272px" />
533
536
 
534
537
  ## Utilities Script
535
538
  The utilities script ([build/js/utils.js](build/js/utils.js)) is a custom build of Google's [libphonenumber](https://github.com/googlei18n/libphonenumber) which enables the following features:
@@ -539,7 +542,7 @@ The utilities script ([build/js/utils.js](build/js/utils.js)) is a custom build
539
542
  * Placeholder set to an example number for the selected country - even specify the type of number (e.g. mobile) using the `placeholderNumberType` option
540
543
  * Extract the standardised (E.164) international number with `getNumber` even when using the `nationalMode` option
541
544
 
542
- International number formatting/validation is hard (it varies by country/district, and we currently support ~230 countries). The only comprehensive solution we have found is libphonenumber, from which we have precompiled the relevant parts into a single JavaScript file and included in the build directory. Unfortunately, even after modification, it is still ~260KB. See the section below on the best way to load it.
545
+ International number formatting/validation is hard (it varies by country/district, and we currently support ~230 countries). The only comprehensive solution we have found is libphonenumber, from which we have precompiled the relevant parts into a single JavaScript file, included in the build directory. Unfortunately, even after modification, it is still ~260KB. See the section below on the best way to load it.
543
546
 
544
547
  To recompile the utils script yourself (e.g. to update the version of libphonenumber it is built from), see the [contributing guide](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md#updating-to-a-new-version-of-libphonenumber).
545
548
 
@@ -550,11 +553,11 @@ The utils script provides lots of great functionality (see above section), but c
550
553
  If you're not concerned about filesize (e.g. you're lazy loading this script), the easiest thing to do is to just use the full bundle /build/js/intlTelInputWithUtils.js, which comes with the utils script included. This script can be used exactly like the main intlTelInput.js - so it can either be loaded directly onto the page (which defines `window.intlTelInput` like usual), or it can be imported like so: `import intlTelInput from "intl-tel-input/intlTelInputWithUtils"`.
551
554
 
552
555
  **Option 2: utilsScript**
553
- If you *are* concerned about filesize, you can lazy load the utils script when the plugin intitialises, using the `utilsScript` initialisation option. You will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.1.3/build/js/utils.js"`. If you want more control over when this file is lazy loaded, you can manually invoke the `loadUtils` static method, instead of using `utilsScript`.
556
+ If you *are* concerned about filesize, you can lazy load the utils script when the plugin initialises, using the `utilsScript` initialisation option. You will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@24.2.1/build/js/utils.js"`. If you want more control over when this file is lazy loaded, you can manually invoke the `loadUtils` static method, instead of using `utilsScript`.
554
557
 
555
558
  ## Troubleshooting
556
559
 
557
- **Full width input**
560
+ **Full-width input**
558
561
  If you want your input to be full-width, you need to set the container to be the same i.e.
559
562
 
560
563
  ```css
@@ -576,13 +579,13 @@ scrollingElement.addEventListener("scroll", function() {
576
579
  For the sake of alignment, the default CSS forces the input's vertical margin to `0px`. If you want vertical margin, you should add it to the container (with class `iti`).
577
580
 
578
581
  **Displaying error messages**
579
- If your error handling code inserts an error message before the `<input>` it will break the layout. Instead you must insert it before the container (with class `iti`).
582
+ If your error handling code inserts an error message before the `<input>` it will break the layout. Instead, you must insert it before the container (with class `iti`).
580
583
 
581
584
  **Dropdown position**
582
585
  The dropdown should automatically appear above/below the input depending on the available space. For this to work properly, you must only initialise the plugin after the `<input>` has been added to the DOM.
583
586
 
584
587
  **Placeholders**
585
- In order to get the automatic country-specific placeholders, simply omit the placeholder attribute on the `<input>`, or set `autoPlaceholder` to `"aggressive"` to override any existing placeholder,
588
+ To get the automatic country-specific placeholders, simply omit the placeholder attribute on the `<input>`, or set `autoPlaceholder` to `"aggressive"` to override any existing placeholder,
586
589
 
587
590
  **Bootstrap input groups**
588
591
  A couple of CSS fixes are required to get the plugin to play nice with Bootstrap [input groups](https://getbootstrap.com/docs/3.3/components/#input-groups). You can see a Codepen [here](https://codepen.io/jackocnr/pen/EyPXed).
@@ -593,7 +596,7 @@ _Note: there is currently [a bug](https://bugs.webkit.org/show_bug.cgi?id=141822
593
596
  ```
594
597
 
595
598
  ## Contributing
596
- See the [contributing guide](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md) for instructions on setting up the project and making changes, and also for how to update to a new version of libphonenumber, how to update the flag images, or how to add a new translation.
599
+ See the [contributing guide](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md) for instructions on setting up the project and making changes, and also on how to update to a new version of libphonenumber, how to update the flag images, or how to add a new translation.
597
600
 
598
601
  ## Attributions
599
602
  * Flag images from [flag-icons](https://github.com/lipis/flag-icons)