Skip to content

Commit

Permalink
Merge pull request frappe#28507 from UmakanthKaspa/feature/multiselec…
Browse files Browse the repository at this point in the history
…t-clear-all

Feat: Add Clear All Button to MultiSelect Field
  • Loading branch information
sumitbhanushali authored Nov 26, 2024
2 parents b72bc3a + 810519d commit 2b43e13
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frappe/public/js/frappe/form/controls/multiselect_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
</li>
<div class="selectable-items">
</div>
<li class="text-right">
<button class="btn btn-primary btn-xs clear-selections text-nowrap">
Clear All
</button>
</li>
</ul>
</div>
`;
Expand All @@ -31,6 +36,9 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
this.$list_wrapper.on("click", ".dropdown-menu", (e) => {
e.stopPropagation();
});
this.$list_wrapper.on("click", ".clear-selections", (e) => {
this.clear_all_selections();
});
this.$list_wrapper.on("click", ".selectable-item", (e) => {
let $target = $(e.currentTarget);
this.toggle_select_item($target);
Expand Down Expand Up @@ -115,6 +123,14 @@ frappe.ui.form.ControlMultiSelectList = class ControlMultiSelectList extends (
}
}

clear_all_selections() {
this.values = [];
this._selected_values = [];
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);
Expand Down

0 comments on commit 2b43e13

Please sign in to comment.