Browse Source

UI: Refactoring

pull/11182/head
Artem Dzhereleiko 2 years ago
parent
commit
50b9d69386
  1. 25
      ui-ngx/src/app/shared/components/entity/entity-list.component.ts

25
ui-ngx/src/app/shared/components/entity/entity-list.component.ts

@ -25,7 +25,15 @@ import {
SimpleChanges, SimpleChanges,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import {
ControlValueAccessor,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
UntypedFormBuilder,
UntypedFormGroup,
ValidationErrors,
Validators
} from '@angular/forms';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { filter, map, mergeMap, share, tap } from 'rxjs/operators'; import { filter, map, mergeMap, share, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@ -49,6 +57,11 @@ import { SubscriptSizing } from '@angular/material/form-field';
provide: NG_VALUE_ACCESSOR, provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => EntityListComponent), useExisting: forwardRef(() => EntityListComponent),
multi: true multi: true
},
{
provide: NG_VALIDATORS,
useExisting: forwardRef(() => EntityListComponent),
multi: true
} }
] ]
}) })
@ -179,10 +192,6 @@ export class EntityListComponent implements ControlValueAccessor, OnInit, AfterV
(entities) => { (entities) => {
this.entities = entities; this.entities = entities;
this.entityListFormGroup.get('entities').setValue(this.entities); this.entityListFormGroup.get('entities').setValue(this.entities);
if(!entities.length && this.required) {
this.modelValue = null;
this.propagateChange(this.modelValue);
}
} }
); );
} else { } else {
@ -193,6 +202,12 @@ export class EntityListComponent implements ControlValueAccessor, OnInit, AfterV
this.dirty = true; this.dirty = true;
} }
validate(): ValidationErrors | null {
return this.entityListFormGroup.valid ? null : {
entities: {valid: false}
};
}
reset() { reset() {
this.entities = []; this.entities = [];
this.entityListFormGroup.get('entities').setValue(this.entities); this.entityListFormGroup.get('entities').setValue(this.entities);

Loading…
Cancel
Save