Browse Source

UI: Entity autocomplete error handling

pull/2663/head
Igor Kulikov 7 years ago
parent
commit
eb4334937c
  1. 18
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

18
ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

@ -228,18 +228,32 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
if (value != null) { if (value != null) {
if (typeof value === 'string') { if (typeof value === 'string') {
const targetEntityType = this.checkEntityType(this.entityTypeValue); 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) => { (entity) => {
this.modelValue = entity.id.id; this.modelValue = entity.id.id;
this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); 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 { } else {
const targetEntityType = this.checkEntityType(value.entityType); 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) => { (entity) => {
this.modelValue = entity.id.id; this.modelValue = entity.id.id;
this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); 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);
}
} }
); );
} }

Loading…
Cancel
Save