jackocnr / intl-tel-input

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

Use for generating a country selector field #1792

Closed brouillon closed 2 months ago

brouillon commented 2 months ago

Hello,

Thanks a lot for the good work ;)

Plugin version

v24.4.0

I just want to know if there is a way to use intl-tel-input for generating in the same form where there is a international input phone, a country selector only select/input with flag and search. All labels and flags are here to generate one so... why not ?

jackocnr commented 2 months ago

There's an example of using the country data from the plugin to generate a simple country <select> element on the demo site.

If you want the search functionality as well, that will be much more complicated - you will need to implement a custom solution. Feel free to copy/adapt some of the code from the plugin tho - this is the main source file, and in there you can search for the generateMarkup function for the code to generate the HTML nodes, and search for the _handleSearchChange function for the logic for filtering the countries when the user types in the input. That should give you a good start at least! Best of luck.