From 175ed7819a1647d87d847add71da4d5cf47a02fc Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Fri, 10 Jun 2022 15:22:58 +0100 Subject: Disable save for invalid TOSCA function Disable save button for invalid TOSCA functions in the TOSCA function modal. Change-Id: I322f59b20faec17ba0edaa412273ee41c0c2675c Issue-ID: SDC-4047 Signed-off-by: andre.schmid --- .../tosca-function/tosca-function.component.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts') diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts index 81e5b473a1..8c983b61b8 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts @@ -48,6 +48,10 @@ export class ToscaFunctionComponent implements OnInit { toscaGetFunctionValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => { const toscaGetFunction: ToscaGetFunction = control.value; + const hasAnyValue = Object.keys(toscaGetFunction).find(key => toscaGetFunction[key]); + if (!hasAnyValue) { + return null; + } const errors: ValidationErrors = {}; if (!toscaGetFunction.sourceName) { errors.sourceName = { required: true }; @@ -105,15 +109,15 @@ export class ToscaFunctionComponent implements OnInit { this.loadToscaFunctions(); this.loadPropertySourceDropdown(); this.initToscaGetFunction(); + } + + private initToscaGetFunction(): void { this.toscaGetFunctionForm.valueChanges.subscribe(toscaGetFunction => { this.onValidityChange.emit(this.toscaGetFunctionForm.valid); if (this.toscaGetFunctionForm.valid) { this.onValidFunction.emit(toscaGetFunction); } - }) - } - - private initToscaGetFunction(): void { + }); if (!this.property.isToscaGetFunction()) { return; } @@ -177,8 +181,8 @@ export class ToscaFunctionComponent implements OnInit { } private resetForm(): void { - this.toscaGetFunction = new ToscaGetFunction(undefined); - this.toscaGetFunctionForm.setValue(new ToscaGetFunction(undefined)); + this.toscaGetFunction = new ToscaGetFunction(); + this.toscaGetFunctionForm.setValue(new ToscaGetFunction()); this.propertySource = undefined; this.selectedProperty = undefined; } -- cgit 1.2.3-korg