Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -3434,6 +3434,19 @@ class Selectpicker {
this.element.classList.add('mobile-device');
}

resetMenuData () {
this.selectpicker.main.data = [];
this.selectpicker.main.elements = [];
this.selectpicker.main.hasMore = false;
this.selectpicker.search.data = [];
this.selectpicker.search.elements = [];
this.selectpicker.search.hasMore = false;
this.selectpicker.current.data = this.selectpicker.main.data;
this.selectpicker.current.elements = this.selectpicker.main.elements;
this.selectpicker.current.hasMore = false;
this.selectpicker.isSearching = false;
}

refresh () {
var that = this;
// update options if data attributes have been changed
Expand All @@ -3444,6 +3457,7 @@ class Selectpicker {
this.render();
this.buildList();
} else {
this.resetMenuData();
this.fetchData(function () {
that.render();
that.buildList();
Expand Down
38 changes: 38 additions & 0 deletions tests/e2e/tags-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,44 @@ test.describe('Tags-style live search editor', () => {
await expect(optionAnchor(picker, 'DELTA')).toBeVisible();
});

test('does not duplicate selected tags after repeated refresh calls', async ({ page }) => {
const id = await page.evaluate(() => {
document.body.innerHTML += `
<select id="tags-editor-refresh" multiple>
<option value="one" selected>Option 1</option>
<option value="two" selected>Option 2</option>
<option value="three">Option 3</option>
</select>
`;

new Selectpicker('#tags-editor-refresh', {
liveSearch: true,
showSelectedTags: true,
openOptions: true
});

return 'tags-editor-refresh';
});

const picker = widget(page, id);

await expect(picker.locator('> .bs-selected-items-external .bs-selected-item')).toHaveCount(2);
await expect(picker.locator('.filter-option-inner-inner')).toHaveText('2 items selected');

await page.evaluate((selectId) => {
const instance = Selectpicker.getInstance('#' + selectId);
instance.refresh();
instance.refresh();
}, id);

await expect(picker.locator('> .bs-selected-items-external .bs-selected-item')).toHaveCount(2);
await expect(picker.locator('> .bs-selected-items-external .bs-selected-item')).toContainText(['Option 1', 'Option 2']);
await expect(picker.locator('.filter-option-inner-inner')).toHaveText('2 items selected');
await expect.poll(async () => page.evaluate((selectId) => {
return Array.from(document.getElementById(selectId).selectedOptions).map(option => option.value);
}, id)).toEqual(['one', 'two']);
});

test('supports checkbox selection indicators and search placeholder fallback', async ({ page }) => {
const id = await page.evaluate(() => {
document.body.innerHTML += `
Expand Down