Revert "Provide tosca function capability to complex type fields in composition view"
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / tosca-function / tosca-get-function / tosca-get-function.component.ts
index 26098b7..a1ed8aa 100644 (file)
@@ -229,7 +229,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
         const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
         if (selectedProperty != null && selectedProperty.isList && formGroupStatus && this.indexListValues.length > 0) {
             this.indexListValues.forEach((indexObject : ToscaIndexObject, index) => {
-                if (indexObject.indexValue == null) {
+                if (indexObject.indexValue == '') {
                     formGroupStatus = false;
                     return;
                 }
@@ -617,17 +617,23 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
     }
 
     indexTokenChange(indexObject : ToscaIndexObject): void {
-        if ((indexObject.indexValue).toLowerCase() === 'index') {
+        if ((indexObject.indexValue).toLowerCase() === 'index' ) {
             this.formValidation();
-            return;
         }
-        let indexTokenValue = Number(indexObject.indexValue);
-        if (isNaN(indexTokenValue)) {
-            indexObject.indexValue = "0";
+
+        const regEx = /^[0-9]*$/;
+        const error = document.getElementById('error');
+
+        if (!(regEx.test(indexObject.indexValue)) && (indexObject.indexValue).toLowerCase() !== 'index') {
+            error.textContent='Invalid value - must be an integer or INDEX';
+            this.onValidityChange.emit({
+                isValid: false,
+                toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
+            });
+        } else {
+            error.textContent='';
             this.formValidation();
-            return;
         }
-        this.formValidation();
     }
 
     showPropertySourceDropdown(): boolean {
@@ -646,6 +652,9 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
         return this.formGroup.get('selectedProperty') as FormControl;
     }
 
+    onChangeIndexValue(index: ToscaIndexObject, value: any) {
+        this.indexTokenChange(index);
+    }
 }
 
 export interface PropertyDropdownValue {