Skip to content

Commit

Permalink
fix: preserve checked items after a search
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
(cherry picked from commit 19f01c9)
  • Loading branch information
akhilnarang authored and mergify[bot] committed May 15, 2024
1 parent 53b5f29 commit ae9cdd2
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions frappe/public/js/frappe/form/multi_select_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ frappe.ui.form.MultiSelectDialog = class MultiSelectDialog {
this.fields = this.get_fields();

this.make();

this.selected_fields = new Set();
}

get_fields() {
Expand Down Expand Up @@ -337,12 +339,25 @@ frappe.ui.form.MultiSelectDialog = class MultiSelectDialog {
if (!$(e.target).is(":checkbox") && !$(e.target).is("a")) {
$(this).find(":checkbox").trigger("click");
}
let name = $(this).attr("data-item-name").trim();
if ($(this).find(":checkbox").is(":checked")) {
me.selected_fields.add(name);
} else {
me.selected_fields.delete(name);
}
});

this.$results.on("click", ".list-item--head :checkbox", (e) => {
this.$results
.find(".list-item-container .list-row-check")
.prop("checked", $(e.target).is(":checked"));
let checked = $(e.target).is(":checked");
this.$results.find(".list-item-container .list-row-check").each(function () {
$(this).prop("checked", checked);
const name = $(this).closest(".list-item-container").attr("data-item-name").trim();
if (checked) {
me.selected_fields.add(name);
} else {
me.selected_fields.delete(name);
}
});
});

this.$parent.find(".input-with-feedback").on("change", () => {
Expand Down Expand Up @@ -510,12 +525,12 @@ frappe.ui.form.MultiSelectDialog = class MultiSelectDialog {

empty_list() {
// Store all checked items
let checked = this.get_checked_items().map((item) => {
return {
let checked = this.results
.filter((result) => this.selected_fields.has(result.name))
.map((item) => ({
...item,
checked: true,
};
});
}));

// Remove **all** items
this.$results.find(".list-item-container").remove();
Expand Down

0 comments on commit ae9cdd2

Please sign in to comment.