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
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
File details
Details for the file django-intl-tel-input-0.1.2.zip
.
File metadata
- Download URL: django-intl-tel-input-0.1.2.zip
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9103a6f5a73d4bef924e10a3962197b8231b43ae8ccc210692b1ce0e49b9b842 |
|
MD5 | 73986dad702d1dc10caabc7ce0716807 |
|
BLAKE2b-256 | 83cc4b232bade58de0dacb5ab12ff47475297b78e33b2a73722e04432c9160c0 |