Skip to main content

A Django form widget implementing intl-tel-input.

Project description

Django intl-tel-input

Build Status Code coverage

A Django form widget for international telephone numbers based on the jQuery plugin intl-tel-input.

This package is pre 1.0, so doesn't implement every feature of intl-tel-input. However, it is well tested, and has been stable in production.

Version support

Tested on the following versions of Python and Django.

Package Version support
Python 2.7, 3.4, 3.5, 3.6, 3.7
Django 1.11, 2.0, 2.1

Installation

Install from PyPI.

pip install django-intl-tel-input

Add intl-tel-input to your INSTALLED_APPS, so Django can find the init script.

...
INSTALLED_APPS += ('intl_tel_input',)
...

Usage

Simply add IntlTelInputWidget to your form field.

from intl_tel_input.widgets import IntlTelInputWidget

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = ['foo', 'bar']
        widgets = {
            'bar': IntlTelInputWidget()
        }
...

With a standard form:

class MyForm(forms.Form):
    tel_number = forms.CharField(widget=IntlTelInputWidget())

...

Form media

Include {{ form.media.css }} in the <head> of your template. This will ensure all styles are parsed before the widget is displayed.

If you have included jQuery at the end of your document, then don't forget to update the template where this widget appears with a {{ form.media.js }}. Put it in a block that allows it to come after jQuery.

If you're using crispy-forms, the static content will be inserted automatically beside the input. To prevent this, be sure to set include_media = False on your form helper.

class MyForm(forms.Form):
...
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.include_media = False
...

If you need to load all JS in the head, you can make the init.js script wait for the document to be ready with the following snippet.

jQuery(document).ready(
  {{ form.media.js }}
);

All this assumes your form context variable is called form.

Options

The widget can be invoked with keyword arguments which translate to the options available in intl-tel-input.

allow_dropdown

Shows the country dropdown. Default: True

default_code

Country code selected by default. Overridden when using auto_geo_ip. Default: 'us'

preferred_countries

Array of countries that will always appear at the top of the dropdown. Default: ['us', 'gb']

auto_geo_ip

When True, freegeoip will be used to autodetect the user's country via Ajax. There is a limit of 15,000 queries per hour, so it should not be used on high-traffic sites. Alternatively use pygeoip, detect server-side, then set the default_code. Default: False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-intl-tel-input-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

django_intl_tel_input-0.2.0-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-intl-tel-input-0.2.0.tar.gz.

File metadata

  • Download URL: django-intl-tel-input-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for django-intl-tel-input-0.2.0.tar.gz
Algorithm Hash digest
SHA256 334c2d84afab2879c3eb21a8120d9233fdd59d86d568c9b1a7ac7674e4c35223
MD5 b3d4ee5184ca108857bc3dbd64e5090c
BLAKE2b-256 f9eec4814480c85b4bb152bb976a634e756a3ff60bfd734e005c3e0fffcb8785

See more details on using hashes here.

File details

Details for the file django_intl_tel_input-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_intl_tel_input-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for django_intl_tel_input-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dc96571a2acfaab1e087d6d6c5379b96a4163e88fe4a650c56d43448d64768d4
MD5 9faf335d2498264b679177620a657f09
BLAKE2b-256 be31c82416126357009cc53b02f504964e7fa6790ef8f27cf9952892680d01c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page