This commit is contained in:
2025-12-24 10:55:40 +08:00
parent eec9d6045c
commit 752bb23571
25 changed files with 2348 additions and 816 deletions

View File

@@ -405,6 +405,8 @@ export class Dropdown {
}
return item;
});
this._var.allChecked = false;
source.forEach(it => delete it.__checked);
if (itemlist.length === 0) {
this._var.selectedList = null;
this._var.label.innerText = r('none', '( None )');
@@ -608,7 +610,7 @@ export class Dropdown {
}
_contains(it, item, valuekey, textkey) {
if (item.children?.length > 0) {
if (Array.isArray(item.children)) {
for (let t of item.children) {
if (it === getValue(t, valuekey, textkey)) {
return true;
@@ -644,8 +646,19 @@ export class Dropdown {
createElement('span', span => {
// events
span.className = 'ui-expandor';
if (Array.isArray(item.children) && item.children.length > 0) {
span.classList.add('active');
function hideChildren(children) {
for (let c of children) {
c.__visible = false;
if (Array.isArray(c.children)) {
hideChildren(c.children);
}
}
}
}
},
createIcon('fa-light', 'caret-down')
createIcon('fa-solid', 'caret-down')
)
);
li.appendChild(wrapper);
@@ -700,16 +713,17 @@ export class Dropdown {
const textkey = this._var.options.textKey;
const template = this._var.options.htmlTemplate;
const htmlkey = this._var.options.htmlKey;
const source = this.source;
if (checkbox.getAttribute('isall') === '1') {
const allchecked = this._var.allChecked = checkbox.checked;
const boxes = this._var.container.querySelectorAll('input.dataitem');
boxes.forEach(box => box.checked = allchecked);
source.forEach(it => it.__checked = allchecked ? 1 : 0);
list = [];
} else {
item.__checked = checkbox.indeterminate ? 2 : checkbox.checked ? 1 : 0;
const all = this._var.container.querySelector('input[isall="1"]');
if (checkbox.checked) {
const source = this.source;
if (source.some(it => it.__checked) == null) {
this._var.allChecked = true;
if (all != null) {
@@ -726,7 +740,7 @@ export class Dropdown {
if (all != null) {
all.checked = false;
}
list = this.source.filter(it => String(getValue(it, valuekey, textkey)) !== val);
list = source.filter(it => String(getValue(it, valuekey, textkey)) !== val);
} else {
list = this.selectedList.filter(it => String(getValue(it, valuekey, textkey)) !== val);
}
@@ -739,7 +753,7 @@ export class Dropdown {
}
this._var.selectedList = list;
if (typeof this.onSelectedList === 'function') {
this.onSelectedList(itemlist);
this.onSelectedList(list);
}
}