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