UI: Entity autocomplete error handling

This commit is contained in:
Igor Kulikov 2020-04-17 15:12:37 +03:00
parent 1e079457c7
commit eb4334937c

View File

@ -228,18 +228,32 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
if (value != null) {
if (typeof value === 'string') {
const targetEntityType = this.checkEntityType(this.entityTypeValue);
this.entityService.getEntity(targetEntityType, value, {ignoreLoading: true}).subscribe(
this.entityService.getEntity(targetEntityType, value, {ignoreLoading: true, ignoreErrors: true}).subscribe(
(entity) => {
this.modelValue = entity.id.id;
this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false});
},
() => {
this.modelValue = null;
this.selectEntityFormGroup.get('entity').patchValue(null, {emitEvent: false});
if (value !== null) {
this.propagateChange(this.modelValue);
}
}
);
} else {
const targetEntityType = this.checkEntityType(value.entityType);
this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true}).subscribe(
this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true, ignoreErrors: true}).subscribe(
(entity) => {
this.modelValue = entity.id.id;
this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false});
},
() => {
this.modelValue = null;
this.selectEntityFormGroup.get('entity').patchValue(null, {emitEvent: false});
if (value !== null) {
this.propagateChange(this.modelValue);
}
}
);
}