[Library | Trunk]: Dashboard inpout fix a bug with required

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58864 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-06-05 14:48:12 +00:00
parent 034fbe3931
commit cd62e76fcb
1 changed files with 6 additions and 7 deletions

View File

@ -31,10 +31,11 @@ export interface Option {
})
export class InputComponent implements OnInit, OnDestroy {
@Input('formInput') formControl: AbstractControl;
@Input('type') type: string = 'text';
@Input('type') type: 'text' | 'textarea' | 'select' | 'checkbox' = 'text';
@Input('label') label: string;
@Input('rows') rows: number = 3;
@Input('options') options: Option[];
public required: boolean = false;
private initValue: any;
constructor() {
@ -42,6 +43,10 @@ export class InputComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.initValue = HelperFunctions.copy(this.formControl.value);
if(this.formControl && this.formControl.validator) {
let validator = this.formControl.validator({} as AbstractControl);
this.required = (validator && validator.required);
}
this.formControl.valueChanges.subscribe(value => {
value = (value === '')?null:value;
if(this.initValue === value) {
@ -53,12 +58,6 @@ export class InputComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {
}
public get required(): boolean {
return this.formControl && this.formControl.validator
&& this.formControl.validator(this.formControl)
&& this.formControl.validator(this.formControl).required;
}
stopPropagation() {
if(event) {
event.stopPropagation();