jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React and Vue components are also included.
https://intl-tel-input.com
MIT License
7.59k stars 1.94k forks source link

countryOrder not reinstated after a search #1645

Closed NickSutton closed 3 months ago

NickSutton commented 4 months ago

Plugin version

v23.0.10

Steps to reproduce

  1. type a country name,
  2. remove the country name

Expected behaviour

Any countries specified in the 'countryOrder' option should be displayed at the top of the list

Actual behaviour

The country list is returned to alphabetical order

Initialisation options

List any options you're using e.g. utilsScript or onlyCountries

countryOrder = 'ca'
jackocnr commented 3 months ago

I assume you mean countryOrder: ['ca'] with the array brackets?

I tried it here: https://codepen.io/jackocnr/pen/xxNrjRM?editors=0010

And it seems to work fine. Can you reproduce the issue in a codepen? You can fork that one if it helps.

NickSutton commented 3 months ago

Hmmm, thanks.

I'm passing in the country code as a variable:

const countryCode = 'gb'
const iti = window.intlTelInput(input, {
  showSelectedDialCode: true,
   separateDialCode: true,
   strictMode: true,
   initialCountry: countryCode,
   countryOrder: [countryCode],
   nationalMode: true
// No utils scripts as I'm loading intlTelInputWithUtils.min.js
});

But have forked your codepen (https://codepen.io/TheMiddle361/pen/ZENyVLx), but can't reproduce the issue... Here's what I'm seeing:

https://github.com/jackocnr/intl-tel-input/assets/24848258/5c56993a-622a-4f98-9fb6-6c2252d77b1c

NickSutton commented 3 months ago

Fixed. It was an issue with initialising the iti variable somewhere. changed to const newIti and it's working the same as the Codepen now.