Add support for annotating a numeric count on dropdown options

This commit is contained in:
Jeremy Stretch 2024-02-09 13:56:53 -05:00
parent f155e3c3d5
commit 7da211e67a
4 changed files with 9 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@ -35,9 +35,10 @@ export class DynamicTomSelect extends TomSelect {
this.valueField = this.input.getAttribute('ts-value-field') || this.settings.valueField;
this.labelField = this.input.getAttribute('ts-label-field') || this.settings.labelField;
this.disabledField = this.input.getAttribute('ts-disabled-field') || this.settings.disabledField;
this.parentField = this.input.getAttribute('ts-parent-field') || null;
this.depthField = this.input.getAttribute('ts-depth-field') || '_depth';
this.descriptionField = this.input.getAttribute('ts-description-field') || 'description';
this.depthField = this.input.getAttribute('ts-depth-field') || '_depth';
this.parentField = this.input.getAttribute('ts-parent-field') || null;
this.countField = this.input.getAttribute('ts-count-field') || null;
// Set the null option (if any)
const nullOption = this.input.getAttribute('data-null-option');
@ -156,6 +157,9 @@ export class DynamicTomSelect extends TomSelect {
let parent: Dict = data[this.parentField] as Dict;
option['parent'] = parent[this.labelField];
}
if (data[this.countField]) {
option['count'] = data[this.countField];
}
if (data[this.disabledField]) {
option['disabled'] = data[this.disabledField];
}

View File

@ -21,6 +21,9 @@ function renderOption(data: TomOption, escape: typeof escape_html) {
if (data['parent']) {
html = `${html} <span class="text-secondary">${escape(data['parent'])}</span>`;
}
if (data['count']) {
html = `${html} <span class="badge">${escape(data['count'])}</span>`;
}
if (data['description']) {
html = `${html}<br /><small class="text-secondary">${escape(data['description'])}</small>`;
}