diff options
Diffstat (limited to 'website/static/admin/js/autocomplete.js')
-rw-r--r-- | website/static/admin/js/autocomplete.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/website/static/admin/js/autocomplete.js b/website/static/admin/js/autocomplete.js new file mode 100644 index 0000000..65c0702 --- /dev/null +++ b/website/static/admin/js/autocomplete.js @@ -0,0 +1,37 @@ +(function($) { + 'use strict'; + var init = function($element, options) { + var settings = $.extend({ + ajax: { + data: function(params) { + return { + term: params.term, + page: params.page + }; + } + } + }, options); + $element.select2(settings); + }; + + $.fn.djangoAdminSelect2 = function(options) { + var settings = $.extend({}, options); + $.each(this, function(i, element) { + var $element = $(element); + init($element, settings); + }); + return this; + }; + + $(function() { + // Initialize all autocomplete widgets except the one in the template + // form used when a new formset is added. + $('.admin-autocomplete').not('[name*=__prefix__]').djangoAdminSelect2(); + }); + + $(document).on('formset:added', (function() { + return function(event, $newFormset) { + return $newFormset.find('.admin-autocomplete').djangoAdminSelect2(); + }; + })(this)); +}(django.jQuery)); |