Skip to content

Instantly share code, notes, and snippets.

@scottwoodall
Last active May 12, 2021 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottwoodall/f98f753841fc8e73261f973825f22e2f to your computer and use it in GitHub Desktop.
Save scottwoodall/f98f753841fc8e73261f973825f22e2f to your computer and use it in GitHub Desktop.
select2.js
up.compiler(".django-select2", function(element) {
var $modal = $(".up-modal-content");
var options = {};
if ($modal.length > 0) {
// https://select2.org/troubleshooting/common-problems
options.dropdownParent = $modal;
options.width = "100%";
}
$(element).djangoSelect2(options);
$(element).on('select2:select', function (e) {
if (element.form.method.toLowerCase() === "get") {
up.submit(element.form);
}
});
return function() {
$(element).select2("destroy");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment