No error on invalid index

Issue-ID: SDC-4534
Signed-off-by: shikha0203 <shivani.khare@est.tech>
Change-Id: I7df59d0b8a362d15d54d1a6b862201fd0caf1e31
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
index a609db4..2d1e26b 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
@@ -36,7 +36,9 @@
   </form>
   <div class="i-sdc-form-item" *ngFor="let indexVal of indexListValues; index as i">
     <label class="i-sdc-form-label required" *ngIf="indexVal.indexFlag">Index</label>
-    <input type="text" *ngIf="indexVal.indexFlag" [(ngModel)]="indexVal.indexValue" (change)="indexTokenChange(indexVal)"/>
+    <input type="text" *ngIf="indexVal.indexFlag" [(ngModel)]="indexVal.indexValue" (change)="indexTokenChange(indexVal)"
+           (input)="onChangeIndexValue(indexVal, $event.target.value)"/>
+    <span id ="error" class="input-error"></span>
     <label class="i-sdc-form-label required" *ngIf="indexVal.nestedFlag">{{dropdownValuesLabel}}</label>
     <select [(ngModel)]="indexVal.indexProperty" *ngIf="indexVal.nestedFlag" (change)="onSubPropertyValueChange(indexVal,i)">
       <option *ngFor="let value of indexVal.subPropertyArray" [ngValue]="value">{{value.propertyLabel}}</option>
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
index 26098b7..a1ed8aa 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
@@ -229,7 +229,7 @@
         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 @@
     }
 
     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 @@
         return this.formGroup.get('selectedProperty') as FormControl;
     }
 
+    onChangeIndexValue(index: ToscaIndexObject, value: any) {
+        this.indexTokenChange(index);
+    }
 }
 
 export interface PropertyDropdownValue {