mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
Allow search and filtering in long multiple choice boxes
This commit is contained in:
@@ -380,21 +380,44 @@ var form_handlers = function (el) {
|
||||
if ($(this).find(".choice-options-all").length > 0) {
|
||||
return;
|
||||
}
|
||||
var $small = $("<small>");
|
||||
var $menu = $("<div>").addClass("choice-options-menu");
|
||||
var $a_all = $("<a>").addClass("choice-options-all").attr("href", "#").text(gettext("All"));
|
||||
var $a_none = $("<a>").addClass("choice-options-none").attr("href", "#").text(gettext("None"));
|
||||
$(this).prepend($small.append($a_all).append(" / ").append($a_none));
|
||||
var $inp_search = $("<input>").addClass("form-control").attr("type", "text").attr("placeholder", gettext("Search query"));
|
||||
var $lbl_tgl = $("<div>").addClass("checkbox menu-checkbox");
|
||||
var $cb_tgl = $("<input>").attr("type", "checkbox").addClass("menu-checkbox");
|
||||
$lbl_tgl.append($("<label>").append($cb_tgl).append(gettext("Selected only")));
|
||||
$menu.append($("<span>").append($a_all).append(" / ").append($a_none))
|
||||
$menu.append($inp_search);
|
||||
$menu.append($lbl_tgl);
|
||||
$(this).prepend($menu);
|
||||
|
||||
$(this).find(".choice-options-none").click(function (e) {
|
||||
$(this).closest(".scrolling-multiple-choice").find("input[type=checkbox]").prop("checked", false);
|
||||
$(this).closest(".scrolling-multiple-choice").find("input[type=checkbox]:not(.menu-checkbox)").prop("checked", false);
|
||||
$cb_tgl.trigger("change");
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
$(this).find(".choice-options-all").click(function (e) {
|
||||
$(this).closest(".scrolling-multiple-choice").find("input[type=checkbox]").prop("checked", true);
|
||||
$(this).closest(".scrolling-multiple-choice").find("input[type=checkbox]:not(.menu-checkbox)").prop("checked", true);
|
||||
$cb_tgl.trigger("change");
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
$cb_tgl.on("change", function (e) {
|
||||
var tgl = $cb_tgl.prop("checked");
|
||||
|
||||
$(this).closest(".scrolling-multiple-choice").find("div.checkbox:not(.menu-checkbox)").each(function () {
|
||||
$(this).toggleClass("sr-only", tgl && !$(this).find("input[type=checkbox]").prop("checked"));
|
||||
})
|
||||
});
|
||||
$inp_search.on("keyup change", function (e) {
|
||||
var term = $inp_search.val().toLowerCase();
|
||||
|
||||
$(this).closest(".scrolling-multiple-choice").find("div.checkbox:not(.menu-checkbox)").each(function () {
|
||||
$(this).toggleClass("hidden", !$(this).text().toLowerCase().includes(term));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
el.find('.select2-static').select2({
|
||||
|
||||
@@ -387,9 +387,8 @@ div.scrolling-multiple-choice, div.scrolling-choice {
|
||||
height: 150px;
|
||||
border: 1px solid $input-border;
|
||||
border-radius: $input-border-radius;
|
||||
padding-left: 15px;
|
||||
overflow-y: auto;
|
||||
padding-top: 5px;
|
||||
padding: 5px 15px;
|
||||
overflow-y: scroll;
|
||||
|
||||
.radio:first-of-type, .checkbox:first-of-type {
|
||||
margin-top: 0;
|
||||
@@ -397,6 +396,29 @@ div.scrolling-multiple-choice, div.scrolling-choice {
|
||||
&.scrolling-multiple-choice-large {
|
||||
height: 350px;
|
||||
}
|
||||
div.choice-options-menu {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
border-bottom: 1px solid $input-border;
|
||||
margin: 0 -15px;
|
||||
padding: 0 15px 5px;
|
||||
span {
|
||||
display: block;
|
||||
}
|
||||
.checkbox {
|
||||
padding-top: 3px;
|
||||
}
|
||||
.form-control {
|
||||
flex: auto 1 1;
|
||||
width: auto;
|
||||
margin: 0 10px 0 10px;
|
||||
font-size: 12px;
|
||||
height: auto;
|
||||
padding: 2px 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
table td > .checkbox {
|
||||
margin: 0;
|
||||
|
||||
Reference in New Issue
Block a user