Merge pull request #34529 from UmakanthKaspa/feature/multiselect-select-all

feat: add select all button to multiSelect field
This commit is contained in:
Ejaaz Khan 2025-11-20 12:24:54 +05:30 committed by GitHub
commit e37f75d599
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,10 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
</li>
<div class="selectable-items">
</div>
<li class="text-right">
<li class="d-flex justify-content-end">
<button class="btn btn-secondary btn-xs select-all-options text-nowrap mr-2">
${__("Select All")}
</button>
<button class="btn btn-primary btn-xs clear-selections text-nowrap">
${__("Clear All")}
</button>
@ -39,6 +42,9 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
this.$list_wrapper.on("click", ".clear-selections", (e) => {
this.clear_all_selections();
});
this.$list_wrapper.on("click", ".select-all-options", (e) => {
this.select_all_options();
});
this.$list_wrapper.on("click", ".selectable-item", (e) => {
let $target = $(e.currentTarget);
this.toggle_select_item($target);
@ -131,6 +137,14 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
this.parse_validate_and_set_in_model("");
}
select_all_options() {
this.values = this._options.map((opt) => opt.value);
this._selected_values = this._options.slice();
this.update_status();
this.set_selectable_items(this._options);
this.parse_validate_and_set_in_model("");
}
toggle_select_item($selectable_item) {
$selectable_item.toggleClass("selected");
let value = decodeURIComponent($selectable_item.data().value);