Skip to content

Commit

Permalink
Add 'clear' case to bs-select plugin
Browse files Browse the repository at this point in the history
Implemented a 'clear' case to the bs-select plugin, allowing users to clear the selection and remove all options. This update also triggers a 'clear.bs.select' event after clearing.
  • Loading branch information
ThomasDev-de committed Nov 15, 2024
1 parent a348f71 commit 9ca4a18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ $('select').bsSelect('method', param);
| `'selectFirst'` | `$('select').bsSelect('selectFirst');` | Selects the first option element |
| `'selectLast'` | `$('select').bsSelect('selectLast');` | Selects the last option element |
| `'selectNone'` | `$('select').bsSelect('selectNone');` | deselects all values |
| `'clear'` | `$('select').bsSelect('clear');` | Empties the Select |
| `'updateOptions'` | `$('select').bsSelect('updateOptions', {buttonClass: 'btn btn-danger',...});` | Changes the settings of the dropdown. |
| `'setBtnClass'` | `$('select').bsSelect('setBtnClass', 'btn btn-danger');` | Behaves like `updateOptions`. The btnClass option is overwritten. |
| `'refresh'` | `$('select').bsSelect('refresh');` | Rebuild the dropdown. This is useful if the options are changed via Javascript. |
Expand All @@ -163,6 +164,7 @@ $('select').bsSelect('method', param);
| shown.bs.select | Fired when the dropdown has been made visible to the user and CSS transitions have completed. |
| refresh.bs.select | Fires when the `refresh` method has been invoked. |
| change.bs.select | Fires when the method `val` has been called. Additional parameters are [valueBefore, valueAfter] |
| clear.bs.select | Fires when the `clear` method has been called. |
| acceptChange.bs.select | If the function onBeforeChange returns true, this event is fired. |
| cancelChange.bs.select | If the function onBeforeChange returns false, this event is fired. |
| update.bs.select | Fires when the method `updateOptions` or `setBtnClass` was called. |
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webcito/bs-select",
"version": "2.1.10",
"version": "2.1.11",
"description": "A jQuery-based plugin for creating customizable Bootstrap-style select dropdowns with various features including search, multi-select, and dynamic updates.",
"minimum-stability": "stable",
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions dist/jquery.bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,13 @@
}
}
break;
case 'clear': {
$select.val(null);
$select.find('option,optgroup').remove();
refresh($select);
trigger($select, 'clear.bs.select');
}
break;
case 'selectLast': {
if (onBeforeChange($select)) {
$select.val(null);
Expand Down
Loading

0 comments on commit 9ca4a18

Please sign in to comment.