From 1ffa21c7b371c43a9984af8d8ee1d9178769807f Mon Sep 17 00:00:00 2001 From: Benson Tsai <82853302+bsontsai@users.noreply.github.com> Date: Tue, 19 Aug 2025 15:59:19 +0900 Subject: [PATCH 1/2] Update MultiSelect.js registry and clearSelected() --- MultiSelect.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/MultiSelect.js b/MultiSelect.js index 836f6de..5e696c9 100644 --- a/MultiSelect.js +++ b/MultiSelect.js @@ -5,8 +5,13 @@ * Released under the MIT license */ class MultiSelect { + static registry = new Map(); // Stores all instances by element ID constructor(element, options = {}) { + // Register this instance + if (element.id) { + MultiSelect.registry.set(element.id, this); + } let defaults = { placeholder: 'Select item(s)', max: null, @@ -256,5 +261,19 @@ class MultiSelect { return this.options.height; } + clearSelected() { + let selectAllButton = this.element.querySelector('.multi-select-all'); + if (!selectAllButton.classList.contains('multi-select-selected')) { + selectAllButton.classList.add('multi-select-selected'); + } + selectAllButton.click(); + } + + // Static helper to fetch instance anywhere + static getById(id) { + return MultiSelect.registry.get(id); + } + } document.querySelectorAll('[data-multi-select]').forEach(select => new MultiSelect(select)); + From 9910fb8dff65c793458168c20c8f37902008c8d9 Mon Sep 17 00:00:00 2001 From: Benson Tsai <82853302+bsontsai@users.noreply.github.com> Date: Tue, 19 Aug 2025 19:45:47 +0900 Subject: [PATCH 2/2] Create clear_demo.html --- clear_demo.html | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 clear_demo.html diff --git a/clear_demo.html b/clear_demo.html new file mode 100644 index 0000000..03ee3c2 --- /dev/null +++ b/clear_demo.html @@ -0,0 +1,133 @@ + + +
+ + +