Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tags #2660

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,14 @@

function showNoResults (searchMatch, searchValue) {
if (!searchMatch.length) {
elementTemplates.noResults.innerHTML = this.options.noneResultsText.replace('{0}', '"' + htmlEscape(searchValue) + '"');
this.$menuInner[0].firstChild.appendChild(elementTemplates.noResults);
this.no_results = true;
if (!this.options.tags) {
elementTemplates.noResults.innerHTML = this.options.noneResultsText.replace('{0}', '"' + htmlEscape(searchValue) + '"');
this.$menuInner[0].firstChild.appendChild(elementTemplates.noResults);
}
return;
}
this.no_results = false;
}

function filterHidden (item) {
Expand Down Expand Up @@ -963,7 +968,8 @@
display: false,
sanitize: true,
sanitizeFn: null,
whiteList: DefaultWhitelist
whiteList: DefaultWhitelist,
tags: false
};

Selectpicker.prototype = {
Expand All @@ -980,13 +986,19 @@
this.selectId = 'bs-select-' + selectId;

element.classList.add('bs-select-hidden');

this.no_results = false;

this.multiple = this.$element.prop('multiple');
this.autofocus = this.$element.prop('autofocus');

if (element.classList.contains('show-tick')) {
this.options.showTick = true;
}

if (this.options.tags) {
this.options.liveSearch = true;
}

this.$newElement = this.createDropdown();

Expand Down Expand Up @@ -3332,6 +3344,15 @@
that.$menuInner.find('.active a').trigger('click', true); // retain active class
$this.trigger('focus');

if (that.options.tags && e.which === keyCodes.ENTER && that.no_results) {
let searchValue = that.$searchbox[0].value;
let newOption = new Option(searchValue, searchValue);
newOption.selected = true;
that.$element[0].appendChild(newOption);
that.$searchbox[0].value = '';
that.refresh();
}

if (!that.options.liveSearch) {
// Prevent screen from scrolling if the user hits the spacebar
e.preventDefault();
Expand Down