Skip to content

A platform for community discussion. Free, open, simple.

DEV: gives sk components a way to trigger a search manually (#9199)

Joffrey JAFFEUXb727e39a4284
diff --git a/app/assets/javascripts/select-kit/components/select-kit.js.es6 b/app/assets/javascripts/select-kit/components/select-kit.js.es6
index 39e167a24e5..828ee6c7654 100644
--- a/app/assets/javascripts/select-kit/components/select-kit.js.es6
+++ b/app/assets/javascripts/select-kit/components/select-kit.js.es6
@@ -231,10 +231,7 @@ export default Component.extend(
});
if (this.selectKit.isExpanded) {
- if (this._searchPromise) {
- cancel(this._searchPromise);
- }
- this._searchPromise = this._searchWrapper(this.selectKit.filter);
+ this.triggerSearch();
}
if (this.computeContent) {
@@ -388,7 +385,7 @@ export default Component.extend(
_debouncedInput(filter) {
this.selectKit.setProperties({ filter, isLoading: true });
- this._searchPromise = this._searchWrapper(filter);
+ this.triggerSearch(filter);
},
_onChangeWrapper(value, items) {
@@ -567,6 +564,15 @@ export default Component.extend(
return content;
},
+ triggerSearch(filter) {
+ if (this._searchPromise) {
+ cancel(this._searchPromise);
+ }
+ this._searchPromise = this._searchWrapper(
+ filter || this.selectKit.filter
+ );
+ },
+
_searchWrapper(filter) {
this.clearErrors();
this.setProperties({ mainCollection: [], "selectKit.isLoading": true });
@@ -869,10 +875,7 @@ export default Component.extend(
this.selectKit.options.filterable || this.selectKit.options.allowAny
});
- if (this._searchPromise) {
- cancel(this._searchPromise);
- }
- this._searchPromise = this._searchWrapper();
+ this.triggerSearch();
this._safeAfterRender(() => {
this._focusFilter();