A Django form widget implementing intl-tel-input.
Project description
A Django form widget for international telephone numbers 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 is well tested, and has been stable in production.
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'
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-intl-tel-input-0.1.3.tar.gz
.
File metadata
- Download URL: django-intl-tel-input-0.1.3.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fdf9026ce2b12853817823063e32291b46a78031e6ab26105d92912046d40e7 |
|
MD5 | 94db9ea4af89833361bb9414b2781974 |
|
BLAKE2b-256 | c0917bad03c0d3cf67cf488a36f6960999c765c431b8171ae0a30f09728a989b |
File details
Details for the file django_intl_tel_input-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: django_intl_tel_input-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec7392ad2f9241493d35371b21261533435103b1c73cd6adeb49249efae42a0a |
|
MD5 | 886451eb036ec64027ee8fbfb7b2a5eb |
|
BLAKE2b-256 | 79b6be9b2ba55db3e530b296eccf7dcda1eb29ca215936d23723d287d201f033 |