From 287b5c443f135bee69a9b32919f481ec40495dbf Mon Sep 17 00:00:00 2001 From: eschcam Date: Tue, 7 Feb 2023 17:27:13 +0000 Subject: Fix handling of default values for VFC properties Issue-ID: SDC-4375 Signed-off-by: eschcam Change-Id: Icb3c1dbbf52266c2021c50f491a7e48efdfb9e55 --- .../property-form-view-model.ts | 19 +++++-------------- .../component-property-form/property-form-view.html | 3 +-- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'catalog-ui/src/app/view-models/forms') diff --git a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts index c20d9fc408..05045c1529 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts +++ b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -77,7 +77,6 @@ interface IPropertyFormViewModelScope extends ng.IScope { getValidationPattern(type:string):RegExp; validateIntRange(value:string):boolean; close():void; - onValueChange():void; onSchemaTypeChange():void; onTypeChange(resetSchema:boolean):void; showSchema():boolean; @@ -150,6 +149,7 @@ export class PropertyFormViewModel { private initResource = ():void => { this.$scope.editPropertyModel.property = new PropertyModel(this.property); this.$scope.editPropertyModel.property.type = this.property.type ? this.property.type : null; + this.$scope.editPropertyModel.property.value = this.property.value ? this.property.value : this.property.defaultValue; this.$scope.constraints = this.property.constraints && this.property.constraints[0] ? this.property.constraints[0]["validValues"] : null; this.initToscaGetFunction(); this.setMaxLength(); @@ -159,7 +159,7 @@ export class PropertyFormViewModel { this.$scope.editPropertyModel.hasGetFunctionValue = this.$scope.editPropertyModel.property.isToscaFunction(); this.$scope.editPropertyModel.isGetFunctionValid = true; } - + private isDataTypeForPropertyType = (property:PropertyModel):boolean=> { property.simpleType = ""; if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) { @@ -172,7 +172,7 @@ export class PropertyFormViewModel { } return true; }; - + private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string):string => { if (!this.$scope.dataTypes[dataTypeName]) { return 'string'; @@ -438,15 +438,6 @@ export class PropertyFormViewModel { this.$uibModalInstance.close(); }; - // put default value when instance value is empty - this.$scope.onValueChange = ():void => { - if (!this.$scope.editPropertyModel.property.value) { - if (this.$scope.isPropertyValueOwner) { - this.$scope.editPropertyModel.property.value = this.$scope.editPropertyModel.property.defaultValue; - } - } - }; - // Add the done button at the footer. this.$scope.footerButtons = [ {'name': 'Save', 'css': 'blue', 'callback': this.$scope.save}, diff --git a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html index bfe7f49aaa..2840e86523 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html +++ b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html @@ -222,7 +222,7 @@ data-ng-pattern="getValidationPattern((editPropertyModel.property.simpleType||editPropertyModel.property.type))" data-ng-model-options="{ debounce: 200 }" data-ng-change="('json'==editPropertyModel.property.type && forms.editForm.value.$setValidity('pattern', validateJson(editPropertyModel.property.value))) - ||(!forms.editForm.value.$error.pattern && ('integer'==editPropertyModel.property.type && forms.editForm.value.$setValidity('pattern', validateIntRange(editPropertyModel.property.value)) || onValueChange()))" + ||(!forms.editForm.value.$error.pattern && ('integer'==editPropertyModel.property.type && forms.editForm.value.$setValidity('pattern', validateIntRange(editPropertyModel.property.value))))" autofocus/>