Search code examples
javascripthtmldjangointl-tel-input

How to use utils.js of intl-tel-input to save the countery code ?how to use javascript provided data into a django app?


I use intl-tel-input to make the users choose the country code to add phone numbers but the main problem is the phone numbers aren't saved with the code and that raises some errors and doesn't show the numbers formatted as I want.

this is the js script I use to show the widget.

<script>
var input = document.querySelector("#phone");
window.intlTelInput(input,({}));
</script>

how can I change this to make the field also saves the country code to the data?

Update: in the docs, it mentioned something about utils.js but i don't really know how to use this with Django as it mentioned something about .ini files which as far as I'm concerned has something to do with php.


Solution

  • I found a workaround for this issue but feel free to show an alternative. I provided value for a default value for the country code so in my code I made the value attribute like +44 or +1 and whenever a user changes the flag this country code will change to the value of the selected country.