jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers
https://intl-tel-input.com
MIT License
7.38k stars 1.93k forks source link

search field if one country? #1632

Closed Morbids closed 3 hours ago

Morbids commented 1 month ago

If you set only one country in onlyCountries, then why display the search field?

jackocnr commented 1 month ago

If you're only allowing a single country, then why even let them open the dropdown? I would set allowDropdown to false in this case.

Morbids commented 1 month ago

I have these settings

"allowDropdown":false, "autoPlaceholder":"off", "dropdownContainer":null, "formatOnDisplay":false, "geoIpLookup":"ipapi", "initialCountry":"ua", "nationalMode":false, "onlyCountries":["ua"], "countryOrder":[], "separateDialCode":true, "useFullscreenPopup":false, "strictMode":true, "utilsScript":"utils.js"

jackocnr commented 1 month ago

Ok. And so does that solve your problem?

Morbids commented 1 month ago

No Here's a video https://watch.wave.video/kBRwJuGj7mFL1M2h

jackocnr commented 1 month ago

separateDialCode requires the dropdown, so it forces allowDropdown to be true. If you want to have allowDropdown: false, you'll need to set separateDialCode: false.

Morbids commented 1 month ago

If separateDialCode is set to false, then the country flag is moved to the other side of the field and the country code disappears. https://watch.wave.video/EBlOELc5SwKfF1Ks

jackocnr commented 1 month ago

Yes, that is how allowDropdown=false works.

From the readme:

if showFlags is enabled we display the selected flag on the right instead because it is just a marker of state

Morbids commented 1 month ago

I understand it. Maybe then at least leave the country code where it was, otherwise it will be deleted...

jackocnr commented 1 month ago

otherwise it will be deleted

Are you concerned that the user will type their international dial code, and then delete it? Why would they do that?

Please can you describe the precise situation you're concerned about, breaking it down into simple steps, from when the plugin is first initialised, and the input is empty.

Morbids commented 1 month ago

When registering a user, if he does not enter the country code (no matter what country), it will not be possible to send an SMS message to the user. Because the SMS gateway requires the country code and the number itself. Not all users enter the country code themselves; most enter the phone number as usual (for example, 0971234567) and it is necessary that the country code already exists.

The question is completely different - is a search field necessary if there is 1 country, or 2 countries, or 3 countries, etc., until how many countries are visible at once in the drop-down list? If they are already visible in the list and there is no need to search there, well, this is purely my opinion. And if there are more countries than are immediately visible in the open list, then the search field is already needed...

jackocnr commented 1 month ago

if he does not enter the country code (no matter what country), it will not be possible to send an SMS message to the user

This is actually incorrect. It's enough for the user to enter their number in national format (without the international dial code), and then if you use getNumber, it will give you the full international number (including the international dial code). This is actually how the plugin is designed to work, which is why we show a national number placeholder by default, to encourage the user to do just this. Note that getNumber requires the utils script to be loaded - see readme on how to load this.

The question is completely different - is a search field necessary if there is 1 country, or 2 countries, or 3 countries, etc.,

Sure. Thanks for raising the question. For me, this is not something that should be decided by the plugin - it should be up to the dev to decide how they want this to work depending on their situation (e.g. it might depend on how many countries you can see at once in the dropdown etc, depending on their custom CSS), so this would require a new option to control it, and in my opinion, this is such an edge case that it's not worth implementing this right now. Especially in your case, where there is only 1 country, it doesn't make any sense to have a dropdown at all.

jackocnr commented 1 day ago

Upon further consideration, if you only want to show say 2-10 countries, then it makes sense to allow the dropdown, but remove the search feature. So I propose we re-add the countrySearch option, which decides if we show the search box or not (as well as the auto-focus functionality), and defaults to true. It should also be forced to true when separateDialCode is true, as that depends on the search feature. I don't have time to implement this myself right now, but I would be open to a pull request.

jackocnr commented 3 hours ago

I've re-added the countrySearch option in v23.4.0