Skip to main content

A Django form widget implementing intl-tel-input.

Project description

A Django form widget based on the jQuery plugin intl-tel-input.

This is a new package, so it doesn’t implement all the features of intl-tel-input. However, it has been stable in testing, so if you’re still down…

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

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 load jQuery in the head of your document, you needn’t worry about this step - widget media will be inserted right after the field. If you want to keep all JS at the end of your document, you can still use the {{ form.media.js }} tag to achieve that. Just make sure it always comes after the form field.

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

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.1.2.zip (9.1 kB view details)

Uploaded Source

File details

Details for the file django-intl-tel-input-0.1.2.zip.

File metadata

File hashes

Hashes for django-intl-tel-input-0.1.2.zip
Algorithm Hash digest
SHA256 9103a6f5a73d4bef924e10a3962197b8231b43ae8ccc210692b1ce0e49b9b842
MD5 73986dad702d1dc10caabc7ce0716807
BLAKE2b-256 83cc4b232bade58de0dacb5ab12ff47475297b78e33b2a73722e04432c9160c0

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