GithubHelp home page GithubHelp logo

isaac12x / django-intl-tel-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benmurden/django-intl-tel-input

0.0 1.0 0.0 47 KB

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

License: Other

JavaScript 13.65% Python 82.56% HTML 3.79%

django-intl-tel-input's Introduction

Django intl-tel-input

image

image

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.

Version support

Tested on the following versions of Python and Django.

Python: 2.7, 3.3, 3.4, 3.5, 3.6 Django: 1.8, 1.9, 1.10, 1.11

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

django-intl-tel-input's People

Contributors

benmurden avatar joseignaciorc avatar sureshvv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.