I have a typehead in page that loads the users of the customer account. After I click one item in typehead results, the users load to the next select box but before I submit, I go and delete that option from typehead, clear it and do an onBlur the other select box still showing results which is wrong.
Where can I delete the options of that box after detecting the typehead value is empty?
Here is HTML and below is the code I feel is relevant.
P.S. I am not en expert in Angular as you can imagine
<div class="form-group">
<label class="control-label">{{ "ASSUME_IDENTITY.LABELS.CUSTOMER" | translate }}</label>
<div>
<ng-template #rt let-r="result" let-t="term">
{{ r.fullPath }}
</ng-template>
<input id="typeahead-format" name="nodeFullPath" type="text" mdbActive [ngClass]="{'invalid': validNode, 'valid': validNode}"
class="form-control" #el (focus)="onFocus($event)" (selectItem)="selectItem($event)" (blur)="onBlurMethod(selectedNode)"
[ngbTypeahead]="search" [resultTemplate]="rt" [inputFormatter]="formatter" />
</div>
</div>
<div class="form-group">
<label class="control-label">{{ "ASSUME_IDENTITY.LABELS.USER" | translate }}</label>
<div>
<select class="form-control" [(ngModel)]="selectedUser" name="selectedUser" [disabled]="!(usersLoaded | async)">
<option *ngFor="let user of (usersForNode | async)" [ngValue]="user"> {{user.label | translate}}</option>
</select>
</div>
</div>
<div>
<button type="button" [disabled]="!(usersLoaded | async)" class=" btn btn-primary pull-right" (click)="assumeIdbuttonPressed()">
{{ "ASSUME_IDENTITY.BTN_ASSUME_IDENTITY" | translate }}</button>
</div>
.....................
setSelectedUserToFirstItem(user: HttpOption) {
this.selectedUser = user;
}
onFocus(e: Event): void {
e.stopPropagation();
setTimeout(() => {
const inputEvent: Event = new Event('input');
e.target.dispatchEvent(inputEvent);
}, 0);
}
search = (text: Observable<string>): Observable<CustomerNodePath[]> =>
text
.debounceTime(100)
.distinctUntilChanged()
.map((term: any) => this.fullPathList.filter(v => v.fullPath.toLowerCase().indexOf(term.toLowerCase()) > -1))
formatter = (x: { fullPath: string }): string => x.fullPath;
selectItem = (event: any) => {
this.selectedNode = event.item;
this.store.dispatch(new GetUsersForNode(this.selectedNode.id));
}
onBlurMethod = (node: CustomerNodePath): void => {
if (!this.selectedNode) this.dispatchNodeValidationError();
}
private dispatchNodeValidationError = (): void => {
this.store.dispatch(new NodeValidationError());
}
This is the solution we have:
Put this in the component.
As you can see there is a new action called ClearUsers registered in the reducer, we are calling that.
This is a new case in Reducer so a new Action too: