|
1 | 1 | Django intl-tel-input |
2 | 2 | ===================== |
3 | 3 |
|
4 | | -.. image:: https://travis-ci.org/benmurden/django-intl-tel-input.svg?branch=master |
5 | | - :target: https://travis-ci.org/benmurden/django-intl-tel-input |
6 | | -.. image:: https://img.shields.io/codecov/c/github/benmurden/django-intl-tel-input.svg |
7 | | - :target: https://codecov.io/gh/benmurden/django-intl-tel-input |
| 4 | +[![image]] |
8 | 5 |
|
9 | | -A Django form widget for international telephone numbers based on the jQuery plugin `intl-tel-input`_. |
| 6 | +[![image][1]] |
10 | 7 |
|
11 | | -This is a new package, so it doesn't implement all the features of |
12 | | -intl-tel-input. However, it is well tested, and has been stable in production. |
| 8 | +A Django form widget for international telephone numbers based on the |
| 9 | +jQuery plugin [intl-tel-input]. |
| 10 | + |
| 11 | +This is a new package, so it doesn\'t implement all the features of |
| 12 | +intl-tel-input. However, it is well tested, and has been stable in |
| 13 | +production. |
13 | 14 |
|
14 | 15 | Version support |
15 | 16 | --------------- |
16 | 17 |
|
17 | 18 | Tested on the following versions of Python and Django. |
18 | 19 |
|
19 | | -Python: 2.7, 3.3, 3.4, 3.5, 3.6 |
| 20 | +Python: 2.7, 3.4, 3.5, 3.6 |
20 | 21 | Django: 1.8, 1.9, 1.10, 1.11 |
21 | 22 |
|
22 | 23 | Installation |
23 | 24 | ------------ |
24 | 25 |
|
25 | 26 | Install from PyPI. |
26 | 27 |
|
27 | | -.. code:: shell |
28 | | -
|
29 | | - pip install django-intl-tel-input |
| 28 | +``` {.sourceCode .shell} |
| 29 | +pip install django-intl-tel-input |
| 30 | +``` |
30 | 31 |
|
31 | 32 | Add intl-tel-input to your INSTALLED\_APPS, so Django can find the init |
32 | 33 | script. |
33 | 34 |
|
34 | | -.. code:: python |
35 | | -
|
36 | | - ... |
37 | | - INSTALLED_APPS += ('intl_tel_input',) |
38 | | - ... |
| 35 | +``` {.sourceCode .python} |
| 36 | +... |
| 37 | +INSTALLED_APPS += ('intl_tel_input',) |
| 38 | +... |
| 39 | +``` |
39 | 40 |
|
40 | 41 | Usage |
41 | 42 | ----- |
42 | 43 |
|
43 | | -Simply add ``IntlTelInputWidget`` to your form field. |
| 44 | +Simply add `IntlTelInputWidget` to your form field. |
44 | 45 |
|
45 | | -.. code:: python |
| 46 | +``` {.sourceCode .python} |
| 47 | +from intl_tel_input.widgets import IntlTelInputWidget |
46 | 48 |
|
47 | | - from intl_tel_input.widgets import IntlTelInputWidget |
48 | | -
|
49 | | - class MyForm(forms.ModelForm): |
50 | | - class Meta: |
51 | | - model = MyModel |
52 | | - fields = ['foo', 'bar'] |
53 | | - widgets = { |
54 | | - 'bar': IntlTelInputWidget() |
55 | | - } |
56 | | - ... |
| 49 | +class MyForm(forms.ModelForm): |
| 50 | + class Meta: |
| 51 | + model = MyModel |
| 52 | + fields = ['foo', 'bar'] |
| 53 | + widgets = { |
| 54 | + 'bar': IntlTelInputWidget() |
| 55 | + } |
| 56 | +... |
| 57 | +``` |
57 | 58 |
|
58 | 59 | With a standard form: |
59 | 60 |
|
60 | | -.. code:: python |
61 | | -
|
62 | | - class MyForm(forms.Form): |
63 | | - tel_number = forms.CharField(widget=IntlTelInputWidget()) |
| 61 | +``` {.sourceCode .python} |
| 62 | +class MyForm(forms.Form): |
| 63 | + tel_number = forms.CharField(widget=IntlTelInputWidget()) |
64 | 64 |
|
65 | | - ... |
| 65 | +... |
| 66 | +``` |
66 | 67 |
|
67 | 68 | Form media |
68 | 69 | ---------- |
69 | 70 |
|
70 | | -Include ``{{ form.media.css }}`` in the ``<head>`` of your template. This will ensure all styles are parsed before the widget is displayed. |
| 71 | +Include `{{ form.media.css }}` in the `<head>` of your template. This |
| 72 | +will ensure all styles are parsed before the widget is displayed. |
71 | 73 |
|
72 | | -If you have included jQuery at the end of your document, then don't |
| 74 | +If you have included jQuery at the end of your document, then don\'t |
73 | 75 | forget to update the template where this widget appears with a |
74 | | -``{{ form.media.js }}``. Put it in a block that allows it to come after |
| 76 | +`{{ form.media.js }}`. Put it in a block that allows it to come after |
75 | 77 | jQuery. |
76 | 78 |
|
77 | | -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. |
| 79 | +If you\'re using [crispy-forms], the static content will be inserted |
| 80 | +automatically beside the input. To prevent this, be sure to set |
| 81 | +`include_media = False` on your form helper. |
| 82 | + |
| 83 | +``` {.sourceCode .python} |
| 84 | +class MyForm(forms.Form): |
| 85 | +... |
| 86 | + def __init__(self, *args, **kwargs): |
| 87 | + self.helper = FormHelper() |
| 88 | + self.helper.include_media = False |
| 89 | +... |
| 90 | +``` |
| 91 | + |
| 92 | +If you need to load all JS in the head, you can make the `init.js` |
| 93 | +script wait for the document to be ready with the following snippet. |
| 94 | + |
| 95 | +``` {.sourceCode .javascript} |
| 96 | +jQuery(document).ready( |
| 97 | + {{ form.media.js }} |
| 98 | +); |
| 99 | +``` |
| 100 | + |
| 101 | +All this assumes your form context variable is called `form`. |
| 102 | + |
| 103 | + [image]: https://travis-ci.org/benmurden/django-intl-tel-input.svg?branch=master |
| 104 | + [![image]]: https://travis-ci.org/benmurden/django-intl-tel-input |
| 105 | + [1]: https://img.shields.io/codecov/c/github/benmurden/django-intl-tel-input.svg |
| 106 | + [![image][1]]: https://codecov.io/gh/benmurden/django-intl-tel-input |
| 107 | + [intl-tel-input]: https://github.com/jackocnr/intl-tel-input |
| 108 | + [crispy-forms]: https://github.com/django-crispy-forms/django-crispy-forms |
78 | 109 |
|
79 | | -.. code:: python |
80 | | -
|
81 | | - class MyForm(forms.Form): |
82 | | - ... |
83 | | - def __init__(self, *args, **kwargs): |
84 | | - self.helper = FormHelper() |
85 | | - self.helper.include_media = False |
86 | | - ... |
87 | | -
|
88 | | -If you need to load all JS in the head, you can make the ``init.js`` script |
89 | | -wait for the document to be ready with the following snippet. |
| 110 | +Options |
| 111 | +======= |
90 | 112 |
|
91 | | -.. code:: javascript |
| 113 | +The widget can be invoked with keyword arguments which translate to the |
| 114 | +options available in intl-tel-input. |
92 | 115 |
|
93 | | - jQuery(document).ready( |
94 | | - {{ form.media.js }} |
95 | | - ); |
96 | | - |
97 | | -All this assumes your form context variable is called ``form``. |
| 116 | +allow\_dropdown |
98 | 117 |
|
99 | | -.. _intl-tel-input: https://github.com/jackocnr/intl-tel-input |
100 | | -.. _crispy-forms: https://github.com/django-crispy-forms/django-crispy-forms |
| 118 | +: Shows the country dropdown. Default: `True` |
101 | 119 |
|
102 | | -Options |
103 | | -------- |
| 120 | +default\_code |
104 | 121 |
|
105 | | -The widget can be invoked with keyword arguments which translate to the options |
106 | | -available in intl-tel-input. |
| 122 | +: Country code selected by default. Overridden when using |
| 123 | + `auto_geo_ip`. Default: `'us'` |
107 | 124 |
|
108 | | -allow_dropdown |
109 | | - Shows the country dropdown. |
110 | | - Default: ``True`` |
| 125 | +preferred\_countries |
111 | 126 |
|
112 | | -default_code |
113 | | - Country code selected by default. Overridden when using ``auto_geo_ip``. |
114 | | - Default: ``'us'`` |
| 127 | +: Array of countries that will always appear at the top of the |
| 128 | + dropdown. Default: `['us', 'gb']` |
115 | 129 |
|
116 | | -preferred_countries |
117 | | - Array of countries that will always appear at the top of the dropdown. |
118 | | - Default: ``['us', 'gb']`` |
| 130 | +auto\_geo\_ip |
119 | 131 |
|
120 | | -auto_geo_ip |
121 | | - 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``. |
122 | | - Default: ``False`` |
| 132 | +: When True, [freegeoip] will be used to autodetect the user\'s |
| 133 | + country via Ajax. There is a limit of 15,000 queries per hour, so it |
| 134 | + should not be used on high-traffic sites. Alternatively use |
| 135 | + [pygeoip], detect server-side, then set the `default_code`. Default: |
| 136 | + `False` |
123 | 137 |
|
124 | | -.. _freegeoip: https://freegeoip.net |
125 | | -.. _pygeoip: https://pypi.python.org/pypi/pygeoip |
| 138 | + [freegeoip]: https://freegeoip.net |
| 139 | + [pygeoip]: https://pypi.python.org/pypi/pygeoip |
0 commit comments