Skip to content

Commit

Permalink
fix(forms): ensure select2 is included last
Browse files Browse the repository at this point in the history
Select2 needs to be initialised AFTER jQuery is added to the global namespace.

This commit also:
- Ensures min-width for the select2 widget, and explicitly initialised the widget
for the first field selected.
- Add latest django context_processors to TEMPLATES.OPTIONS setting
  • Loading branch information
asfaltboy committed Feb 26, 2017
1 parent e9d5421 commit f6cd55e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,5 @@ tests/db.sqlite*
/.eggs/
/htmlcov/
/advanced_filters/.coverage

/tests/local.db
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -30,6 +30,8 @@ Requirements
- django-braces == 1.4.0
- simplejson == 3.6.5

*NOTE*: While the latest Django 1.5.X is supported, the bundled jQuery it includes is outdated (1.4.2) and as such, most of our admin frontend scripts fail. This means that to use advanced-filters in Django 1.5 admin, you'd have to probably include your own jQuery (1.9 or later) and add it to global namespace prior to other scripts in `AdvancedFilterForm.Meta`.

Installation & Set up
=====================

Expand Down
2 changes: 1 addition & 1 deletion advanced_filters/forms.py
Expand Up @@ -252,7 +252,7 @@ class Media:
('' if settings.DEBUG else '.min')),
static('magnific-popup/jquery.magnific-popup.js'),
static('advanced-filters/advanced-filters.js'), ]
js = [SELECT2_JS] + required_js
js = required_js + [SELECT2_JS]
css = {'screen': [static(SELECT2_CSS), static('advanced-filters/advanced-filters.css'),
static('magnific-popup/magnific-popup.css')]}

Expand Down
4 changes: 4 additions & 0 deletions advanced_filters/static/advanced-filters/advanced-filters.css
Expand Up @@ -66,4 +66,8 @@
}
.empty-form {
display: none;
}

.select2-container {
min-width: 166px;
}
2 changes: 2 additions & 0 deletions advanced_filters/static/advanced-filters/advanced-filters.js
Expand Up @@ -127,6 +127,8 @@ var OperatorHandlers = function($) {
$(this).data('pre_change', $(this).val());
}).change();
});
self.field_selected($('.form-row select.query-field').first());

};

self.destroy = function() {
Expand Down
14 changes: 14 additions & 0 deletions tests/test_project/settings.py
Expand Up @@ -58,6 +58,20 @@
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
}
},
]

Expand Down

0 comments on commit f6cd55e

Please sign in to comment.