summaryrefslogtreecommitdiff
path: root/ishtar_common/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r--ishtar_common/widgets.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index b0f28a6cf..42a93ddaa 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -58,7 +58,7 @@ class Select2Multiple(forms.SelectMultiple):
css = {
'all': ('select2/css/select2.css',)
}
- js = ['select2/js/select2.min.js']
+ js = ['select2/js/select2.full.min.js']
for lang_code, lang in settings.LANGUAGES:
js.append('select2/js/i18n/{}.js'.format(lang_code))
media.add_css(css)
@@ -82,12 +82,20 @@ class Select2Multiple(forms.SelectMultiple):
self.remote = None
if not choices and not self.remote and self.model:
choices = self.get_choices()
+ new_attrs = self.attrs.copy()
+ new_attrs.update(attrs)
+ attrs = new_attrs
klass = attrs and attrs.get('class') or ''
klass += ' ' if klass else '' + 'js-select2'
if not attrs:
attrs = {}
attrs['class'] = klass
- attrs['style'] = "width: 370px"
+ if 'style' not in attrs:
+ if attrs.get('full-width', None):
+ attrs['style'] = "width: 100%"
+ else:
+ attrs['style'] = "width: 370px"
+
options = ""
if self.remote:
options = """{
@@ -120,6 +128,12 @@ class Select2Multiple(forms.SelectMultiple):
except (self.model.DoesNotExist, ValueError):
# an old reference? it should not happen
pass
+ if attrs.get('full-width', None):
+ if options:
+ options = options[:-1] + ", "
+ else:
+ options = "{"
+ options += " containerCssClass: 'full-width'}"
html = super(Select2Multiple, self).render(name, value, attrs,
choices)
html += """<script type="text/javascript">