Skip to content

Commit

Permalink
ensure button text is updated after selecting option (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjhol committed Apr 17, 2020
1 parent ef1b2d2 commit f0e84ed
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,9 +1653,9 @@

render: function () {
var that = this,
// ensure titleOption is appended and selected (if necessary) before getting selectedOptions
startIndex = this.setPlaceholder() ? 1 : 0,
element = this.$element[0],
// ensure titleOption is appended and selected (if necessary) before getting selectedOptions
placeholderSelected = this.setPlaceholder() && element.selectedIndex === 0,
selectedOptions = getSelectedOptions(element, this.options.hideDisabled),
selectedCount = selectedOptions.length,
button = this.$button[0],
Expand Down Expand Up @@ -1683,40 +1683,42 @@

// only loop through all selected options if the count won't be shown
if (showCount === false) {
for (var selectedIndex = startIndex; selectedIndex < selectedCount; selectedIndex++) {
if (selectedIndex < 50) {
var option = selectedOptions[selectedIndex],
thisData = this.selectpicker.main.data[option.liIndex],
titleOptions = {};

if (this.multiple && selectedIndex > 0) {
titleFragment.appendChild(multipleSeparator.cloneNode(false));
}
if (!placeholderSelected) {
for (var selectedIndex = 0; selectedIndex < selectedCount; selectedIndex++) {
if (selectedIndex < 50) {
var option = selectedOptions[selectedIndex],
thisData = this.selectpicker.main.data[option.liIndex],
titleOptions = {};

if (this.multiple && selectedIndex > 0) {
titleFragment.appendChild(multipleSeparator.cloneNode(false));
}

if (option.title) {
titleOptions.text = option.title;
} else if (thisData) {
if (thisData.content && that.options.showContent) {
titleOptions.content = thisData.content.toString();
hasContent = true;
} else {
if (that.options.showIcon) {
titleOptions.icon = thisData.icon;
if (option.title) {
titleOptions.text = option.title;
} else if (thisData) {
if (thisData.content && that.options.showContent) {
titleOptions.content = thisData.content.toString();
hasContent = true;
} else {
if (that.options.showIcon) {
titleOptions.icon = thisData.icon;
}
if (that.options.showSubtext && !that.multiple && thisData.subtext) titleOptions.subtext = ' ' + thisData.subtext;
titleOptions.text = option.textContent.trim();
}
if (that.options.showSubtext && !that.multiple && thisData.subtext) titleOptions.subtext = ' ' + thisData.subtext;
titleOptions.text = option.textContent.trim();
}
}

titleFragment.appendChild(generateOption.text.call(this, titleOptions, true));
} else {
break;
titleFragment.appendChild(generateOption.text.call(this, titleOptions, true));
} else {
break;
}
}
}

// add ellipsis
if (selectedCount > 49) {
titleFragment.appendChild(document.createTextNode('...'));
// add ellipsis
if (selectedCount > 49) {
titleFragment.appendChild(document.createTextNode('...'));
}
}
} else {
var optionSelector = ':not([hidden]):not([data-hidden="true"]):not([data-divider="true"])';
Expand Down

0 comments on commit f0e84ed

Please sign in to comment.