mybuddy/static/admin/js/autocomplete.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-10-24 02:58:05 +00:00
'use strict';
{
const $ = django.jQuery;
const init = function($element, options) {
const settings = $.extend({
ajax: {
data: function(params) {
return {
term: params.term,
page: params.page
};
}
}
}, options);
$element.select2(settings);
};
$.fn.djangoAdminSelect2 = function(options) {
2020-10-24 02:58:05 +00:00
const settings = $.extend({}, options);
$.each(this, function(i, element) {
2020-10-24 02:58:05 +00:00
const $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));
2020-10-24 02:58:05 +00:00
}