UI: Fixed clear and add an object at LwM2M device profile
This commit is contained in:
parent
ae667e5af1
commit
0301c1e32c
@ -40,7 +40,7 @@
|
||||
class="tb-autocomplete"
|
||||
[displayWith]="displayObjectLwm2mFn">
|
||||
<mat-option *ngFor="let objectLwm2m of filteredObjectsList | async" [value]="objectLwm2m">
|
||||
<span [innerHTML]="objectLwm2m.keyId + ': ' + objectLwm2m.name | highlight:searchText"></span>
|
||||
<span [innerHTML]="objectLwm2m.keyId + ': ' + (objectLwm2m.name | highlight: searchText)"></span>
|
||||
</mat-option>
|
||||
<mat-option *ngIf="!(filteredObjectsList | async)?.length" [value]="null">
|
||||
<span>
|
||||
|
||||
@ -112,15 +112,15 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
||||
ngOnInit() {
|
||||
this.filteredObjectsList = this.lwm2mListFormGroup.get('objectLwm2m').valueChanges
|
||||
.pipe(
|
||||
distinctUntilChanged(),
|
||||
tap((value) => {
|
||||
if (value && typeof value !== 'string') {
|
||||
if (value && !isString(value)) {
|
||||
this.add(value);
|
||||
} else if (value === null) {
|
||||
this.clear();
|
||||
this.clear(this.objectInput.nativeElement.value);
|
||||
}
|
||||
}),
|
||||
filter(searchText => isString(searchText)),
|
||||
distinctUntilChanged(),
|
||||
mergeMap(searchText => this.fetchListObjects(searchText)),
|
||||
share()
|
||||
);
|
||||
@ -176,8 +176,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
||||
}
|
||||
}
|
||||
|
||||
displayObjectLwm2mFn = (object?: ObjectLwM2M): string | undefined => {
|
||||
return object ? object.name : undefined;
|
||||
displayObjectLwm2mFn = (object?: ObjectLwM2M): string => {
|
||||
return object ? object.name : '';
|
||||
}
|
||||
|
||||
private fetchListObjects = (searchText: string): Observable<Array<ObjectLwM2M>> => {
|
||||
@ -196,9 +196,9 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
||||
}
|
||||
}
|
||||
|
||||
private clear() {
|
||||
this.searchText = '';
|
||||
this.lwm2mListFormGroup.get('objectLwm2m').patchValue(null, {emitEvent: false});
|
||||
private clear(value: string = '') {
|
||||
this.objectInput.nativeElement.value = value;
|
||||
this.lwm2mListFormGroup.get('objectLwm2m').patchValue(value);
|
||||
setTimeout(() => {
|
||||
this.objectInput.nativeElement.blur();
|
||||
this.objectInput.nativeElement.focus();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user