1212class IntlTelInputWidget (forms .TextInput ):
1313 input_type = 'tel'
1414
15- class Media :
16- css = {
17- 'all' : (
18- 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/'
19- '{version}/css/intlTelInput.css' .format (
20- version = INTL_TEL_INPUT_VERSION
21- ),
22- ),
23- }
24- js = (
25- 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/'
26- '{version}/js/intlTelInput-jquery.min.js' .format (
27- version = INTL_TEL_INPUT_VERSION
28- ),
29- )
30-
3115 def __init__ (self , attrs = None , allow_dropdown = True ,
3216 preferred_countries = ['us' , 'gb' ], default_code = 'us' ,
3317 use_default_init = True ):
3418
35- if use_default_init :
36- self .Media .js += ('intl_tel_input/init.js' ,)
19+ self .use_default_init = use_default_init
3720
3821 final_attrs = {
3922 'size' : '20' ,
@@ -47,6 +30,30 @@ def __init__(self, attrs=None, allow_dropdown=True,
4730
4831 super (IntlTelInputWidget , self ).__init__ (attrs = final_attrs )
4932
33+ @property
34+ def media (self ):
35+ js = (
36+ 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/'
37+ '{version}/js/intlTelInput-jquery.min.js' .format (
38+ version = INTL_TEL_INPUT_VERSION
39+ ),
40+ )
41+
42+ if self .use_default_init :
43+ js += ('intl_tel_input/init.js' ,)
44+
45+ return forms .Media (
46+ css = {
47+ 'all' : (
48+ 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/'
49+ '{version}/css/intlTelInput.css' .format (
50+ version = INTL_TEL_INPUT_VERSION
51+ ),
52+ ),
53+ },
54+ js = js
55+ )
56+
5057 def render (self , name , value , renderer = None , attrs = None ):
5158 if value is None :
5259 value = ''
0 commit comments