mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-29 12:50:55 +02:00
add static files
This commit is contained in:
37
static/admin/js/autocomplete.js
Normal file
37
static/admin/js/autocomplete.js
Normal file
@ -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));
|
Reference in New Issue
Block a user