From 85b1c6d316889614c1a2f7a4bae69009bee8607f Mon Sep 17 00:00:00 2001 From: Manel Clos Date: Fri, 19 Feb 2016 10:11:13 +0100 Subject: [PATCH] show formats selector only when export action is selected --- import_export/admin.py | 3 +++ import_export/static/import_export/action_formats.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 import_export/static/import_export/action_formats.js diff --git a/import_export/admin.py b/import_export/admin.py index 703b629c1..805172ccb 100644 --- a/import_export/admin.py +++ b/import_export/admin.py @@ -437,6 +437,9 @@ def export_admin_action(self, request, queryset): actions = [export_admin_action] + class Media: + js = ['import_export/action_formats.js'] + class ImportExportActionModelAdmin(ImportMixin, ExportActionModelAdmin): """ diff --git a/import_export/static/import_export/action_formats.js b/import_export/static/import_export/action_formats.js new file mode 100644 index 000000000..6a03ddd2c --- /dev/null +++ b/import_export/static/import_export/action_formats.js @@ -0,0 +1,12 @@ +(function($) { + $(document).on('ready', function() { + $('select[name="action"]', '#changelist-form').on('change', function() { + if ($(this).val() == 'export_admin_action') { + $('select[name="file_format"]', '#changelist-form').parent().show(); + } else { + $('select[name="file_format"]', '#changelist-form').parent().hide(); + } + }); + $('select[name="action"]', '#changelist-form').change(); + }); +})(django.jQuery);