diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts index 1cfb626d6..da219fee6 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts @@ -10,8 +10,12 @@ import { Component, Input, ViewEncapsulation, OnInit } from '@angular/core'; ], encapsulation: ViewEncapsulation.None }) -export class DynamicFieldCheckBoxComponent { +export class DynamicFieldCheckBoxComponent implements OnInit { + @Input() field: Field; @Input() form: FormGroup; + ngOnInit(): void { + if (this.form.get('value').value === null) { this.form.get('value').patchValue(false); } + } } diff --git a/dmp-frontend/src/app/models/Field.ts b/dmp-frontend/src/app/models/Field.ts index 63c25655f..aef8ed7bc 100644 --- a/dmp-frontend/src/app/models/Field.ts +++ b/dmp-frontend/src/app/models/Field.ts @@ -41,9 +41,9 @@ export class Field extends BaseModel implements Serializable, FormGenerat this.defaultValue = JsonSerializer.fromJSONObject(item.defaultValue, DefaultValue); this.value = this.defaultValue.value && !item.value ? this.defaultValue.value : item.value; //this.multiplicity = new Multiplicity(); - // if (this.viewStyle.renderStyle === 'checkBox') { - // this.value = this.value === 'true'; - // } + if (this.viewStyle.renderStyle === 'checkBox') { + this.value = this.value === 'true'; + } //this.multiplicity.max = 2; if (item.multiplicityItems) { this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, Field); } this.data = item.data; diff --git a/dmp-frontend/src/app/utilities/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/utilities/visibility-rules/visibility-rules.service.ts index 08b80f59f..c49cddf4a 100644 --- a/dmp-frontend/src/app/utilities/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/utilities/visibility-rules/visibility-rules.service.ts @@ -55,7 +55,7 @@ export class VisibilityRulesService { private evaluateVisibility(visibilityRule: VisibilityRule) { for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) { const pathKey = this.fieldsPathMemory[visibilityRule.sourceVisibilityRules[i].sourceControlId]; - if (this.formGroup.get(pathKey + '.value') && ((this.formGroup.get(pathKey + '.value').value == null || this.formGroup.get(pathKey + '.value').value == null) || '' + this.formGroup.get(pathKey + '.value').value !== '' + visibilityRule.sourceVisibilityRules[i].sourceControlValue)) { + if (this.formGroup.get(pathKey + '.value') && (this.parseValue(this.formGroup.get(pathKey + '.value').value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) { if (this.formGroup.get(pathKey).parent.get('id')) { if (!this.checkElementVisibility(this.formGroup.get(pathKey).parent.get('id').value)) { const targetPathKey = this.fieldsPathMemory[visibilityRule.targetControlId]; @@ -88,20 +88,11 @@ export class VisibilityRulesService { } } - // deleteFromModel(path: string, obj: any) { - // if (!path) return - // const _obj = JSON.parse(JSON.stringify(obj)); - // const keys = path.split('.'); - - // keys.reduce((acc, key, index) => { - // if (index === keys.length - 1) { - // delete acc[key]; - // return true; - // } - // return acc[key]; - // }, _obj); - // return _obj; - // } + parseValue(value: any) { + if (typeof value === 'string') { + if (value === 'true') { return true; } else if (value === 'false') { return false; } else { return value; } + } else { return value; } + } updateValue(obj, value, path) { let i;