Support passing current term from input-select search to create dialog e.g. for doc type / correspondent

This commit is contained in:
Michael Shamoon
2021-03-24 12:21:13 -07:00
parent 8781ebbadd
commit 567161b2c0
4 changed files with 27 additions and 9 deletions

View File

@@ -10,11 +10,12 @@
bindLabel="name"
bindValue="id"
(change)="onChange(value)"
(blur)="onTouched()">
(search)="onSearch($event)"
(focus)="onFocus()">
</ng-select>
<div *ngIf="showPlusButton()" class="input-group-append">
<button class="btn btn-outline-secondary" type="button" (click)="createNew.emit()">
<button class="btn btn-outline-secondary" type="button" (click)="clickNew()">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg>
@@ -27,7 +28,7 @@
<ng-container *ngFor="let s of getSuggestions()">
<a (click)="value = s.id; onChange(value)" [routerLink]="">{{s.name}}</a>&nbsp;
</ng-container>
</small>
</div>

View File

@@ -34,7 +34,9 @@ export class SelectComponent extends AbstractInputComponent<number> {
suggestions: number[]
@Output()
createNew = new EventEmitter()
createNew = new EventEmitter<string>()
private _lastSearchTerm: string
showPlusButton(): boolean {
return this.createNew.observers.length > 0
@@ -48,4 +50,17 @@ export class SelectComponent extends AbstractInputComponent<number> {
}
}
clickNew() {
this.createNew.next(this._lastSearchTerm)
this._lastSearchTerm = null
}
onFocus() {
this._lastSearchTerm = null
}
onSearch($event) {
this._lastSearchTerm = $event.term
}
}