Skip to content

Commit

Permalink
feat: sort multicheck by label (#23985)
Browse files Browse the repository at this point in the history
* feat: sort multicheck by label

* fix: avoid double translation

* fix: always cast to string before comparing

---------

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
(cherry picked from commit 3527489)
  • Loading branch information
barredterra authored and mergify[bot] committed Dec 28, 2023
1 parent d17c79d commit 5cad670
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions frappe/public/js/frappe/form/controls/multicheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ frappe.ui.form.ControlMultiCheck = class ControlMultiCheck extends frappe.ui.for
make_checkboxes() {
this.$load_state.hide();
this.$checkbox_area.empty();
this.options.forEach((option) => {
let checkbox = this.get_checkbox_element(option).appendTo(this.$checkbox_area);
if (option.danger) {
checkbox.find(".label-area").addClass("text-danger");
}
option.$checkbox = checkbox;
});
this.options
.sort((a, b) => cstr(a.label).localeCompare(cstr(b.label)))
.forEach((option) => {
let checkbox = this.get_checkbox_element(option).appendTo(this.$checkbox_area);
if (option.danger) {
checkbox.find(".label-area").addClass("text-danger");
}
option.$checkbox = checkbox;
});
if (this.df.select_all) {
this.setup_select_all();
}
Expand Down Expand Up @@ -152,7 +154,7 @@ frappe.ui.form.ControlMultiCheck = class ControlMultiCheck extends frappe.ui.for
<div class="checkbox unit-checkbox">
<label title="${option.description || ""}">
<input type="checkbox" data-unit="${option.value}"></input>
<span class="label-area" data-unit="${option.value}">${__(option.label)}</span>
<span class="label-area" data-unit="${option.value}">${option.label}</span>
</label>
</div>
`);
Expand Down

0 comments on commit 5cad670

Please sign in to comment.