Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[41718] Allow ng-select internal filter when no backend API involved

Oliver Günther870b9e839262
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
index 3cbf8a5ac3d..63219386322 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
@@ -4,7 +4,7 @@
[(ngModel)]="model"
[items]="results$ | async"
[ngClass]="classes"
- [typeahead]="typeahead"
+ [typeahead]="boundTypeahead"
[clearOnBackspace]="clearOnBackspace"
[clearSearchOnAdd]="clearSearchOnAdd"
[hideSelected]="hideSelected"
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
index 3a87a0ab073..b61e8520780 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -11,6 +11,7 @@ import {
Input,
NgZone,
OnChanges,
+ OnInit,
Output,
SimpleChanges,
TemplateRef,
@@ -60,7 +61,7 @@ import { OpAutocompleterOptionTemplateDirective } from './directives/op-autocomp
// it has all inputs and outputs of ng-select
// in order to use it, you only need to pass the data type and its filters
// you also can change the value of ng-select default options by changing @inputs and @outputs
-export class OpAutocompleterComponent extends UntilDestroyedMixin implements AfterViewInit, OnChanges {
+export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit, OnChanges {
@HostBinding('class.op-autocompleter') className = true;
@Input() public filters?:IAPIFilter[] = [];
@@ -177,6 +178,9 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public typeahead:BehaviorSubject<string|null> = new BehaviorSubject(null);
+ // We only bind the typeahead to ng-select if we filter values from the backend
+ public boundTypeahead:Subject<string|null>;
+
// a function for setting the options of ng-select
@Input() public getOptionsFn:(searchTerm:string) => Observable<unknown>;
@@ -235,6 +239,12 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
super();
}
+ ngOnInit() {
+ if (!!this.getOptionsFn || this.defaultData) {
+ this.boundTypeahead = this.typeahead;
+ }
+ }
+
ngOnChanges(changes:SimpleChanges):void {
if (changes.items) {
this.items$.next(changes.items.currentValue);