Skip to content

Commit

Permalink
Merge pull request #190 from bullinger-digital/fix-pb-combo-box-items
Browse files Browse the repository at this point in the history
fix(pb-combo-box): Clear items before refetching (fixes #189)
  • Loading branch information
wolfgangmm authored Nov 20, 2024
2 parents ad91741 + b6fdf68 commit e0f123f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pb-combo-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export class PbComboBox extends pbMixin(LitElement) {
},
/**
* Preload all items from the remote data source at startup
* Must be of type string because tom-select supports setting
* that property to "focus" (load data on focus)
*/
preload: {
type: Boolean
type: String
},
/**
* Name of the event to be emitted when the user leaves the form control
Expand Down Expand Up @@ -160,6 +162,12 @@ export class PbComboBox extends pbMixin(LitElement) {
options.searchField = [];
options.preload = this.preload;
options.load = (query, callback) => {
if (this._select) {
// The default behaviour of tom-select is to keep existing items when loading
// again from the source. We want to show only items the server provides, so
// we need to clear "stale" items before fetching.
this._select.clearOptions();
}
fetch(`${url}?query=${encodeURIComponent(query)}`, {
method: 'GET',
mode: 'cors',
Expand Down

0 comments on commit e0f123f

Please sign in to comment.