Skip to content

Commit

Permalink
Refactor selection logic and re-enable settings retrieval
Browse files Browse the repository at this point in the history
Simplify variable names in the `val` function and ensure settings retrieval for relevant actions. This refactor enhances code readability and maintains functionality by minimizing redundancy and reusing existing logic effectively.
  • Loading branch information
ThomasDev-de committed Nov 15, 2024
1 parent 6568f04 commit a348f71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions dist/jquery.bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,21 +887,18 @@
*
* @*/
function val($select) {

// const settings = $select.data('options');
// const multiple = false !== $select.prop('multiple');
const $dropdown = getDropDown($select);
const beforeValues = $select.val();
$dropdown.find('.dropdown-item.active').removeClass('active');
$dropdown.find('.dropdown-item .js-icon-checklist.bi-check-square').removeClass('bi-check-square').addClass('bi-square');
const disabledDropdownIcons = $dropdown.find('.dropdown-item.disabled');
disabledDropdownIcons.removeClass('disabled');
let selectedValues = $select.val();
if (!Array.isArray(selectedValues)) {
selectedValues = [selectedValues];
let values = beforeValues;
if (!Array.isArray(values)) {
values = [values];
}

selectedValues.forEach(value => {
values.forEach(value => {
let index = $select.find(`option[value="${value}"]`).index();
const item = $dropdown.find(`.dropdown-item[data-index="${index}"]`);
item.addClass('active');
Expand Down Expand Up @@ -1073,6 +1070,8 @@

if (callFunction) {

const settings = $select.data('options');

switch (options) {
case 'getSelectedText': {
let result; // Variable zum Speichern des Ergebnisses
Expand Down Expand Up @@ -1115,6 +1114,7 @@
if (onBeforeChange($select)) {
$select.val(null);
$select.find('option').first().attr('selected', true);

val($select);
}
}
Expand Down
Loading

0 comments on commit a348f71

Please sign in to comment.