Fixed Issue With Visibility Service on initial values

This commit is contained in:
Ioannis Kalyvas 2018-10-22 12:37:55 +03:00
parent 7cc9854f11
commit 38d356703a
3 changed files with 14 additions and 19 deletions

View File

@ -10,8 +10,12 @@ import { Component, Input, ViewEncapsulation, OnInit } from '@angular/core';
], ],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class DynamicFieldCheckBoxComponent { export class DynamicFieldCheckBoxComponent implements OnInit {
@Input() field: Field; @Input() field: Field;
@Input() form: FormGroup; @Input() form: FormGroup;
ngOnInit(): void {
if (this.form.get('value').value === null) { this.form.get('value').patchValue(false); }
}
} }

View File

@ -41,9 +41,9 @@ export class Field extends BaseModel implements Serializable<Field>, FormGenerat
this.defaultValue = JsonSerializer.fromJSONObject(item.defaultValue, DefaultValue); this.defaultValue = JsonSerializer.fromJSONObject(item.defaultValue, DefaultValue);
this.value = this.defaultValue.value && !item.value ? this.defaultValue.value : item.value; this.value = this.defaultValue.value && !item.value ? this.defaultValue.value : item.value;
//this.multiplicity = new Multiplicity(); //this.multiplicity = new Multiplicity();
// if (this.viewStyle.renderStyle === 'checkBox') { if (this.viewStyle.renderStyle === 'checkBox') {
// this.value = this.value === 'true'; this.value = this.value === 'true';
// } }
//this.multiplicity.max = 2; //this.multiplicity.max = 2;
if (item.multiplicityItems) { this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, Field); } if (item.multiplicityItems) { this.multiplicityItems = JsonSerializer.fromJSONArray(item.multiplicityItems, Field); }
this.data = item.data; this.data = item.data;

View File

@ -55,7 +55,7 @@ export class VisibilityRulesService {
private evaluateVisibility(visibilityRule: VisibilityRule) { private evaluateVisibility(visibilityRule: VisibilityRule) {
for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) { for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) {
const pathKey = this.fieldsPathMemory[visibilityRule.sourceVisibilityRules[i].sourceControlId]; 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.formGroup.get(pathKey).parent.get('id')) {
if (!this.checkElementVisibility(this.formGroup.get(pathKey).parent.get('id').value)) { if (!this.checkElementVisibility(this.formGroup.get(pathKey).parent.get('id').value)) {
const targetPathKey = this.fieldsPathMemory[visibilityRule.targetControlId]; const targetPathKey = this.fieldsPathMemory[visibilityRule.targetControlId];
@ -88,20 +88,11 @@ export class VisibilityRulesService {
} }
} }
// deleteFromModel(path: string, obj: any) { parseValue(value: any) {
// if (!path) return if (typeof value === 'string') {
// const _obj = JSON.parse(JSON.stringify(obj)); if (value === 'true') { return true; } else if (value === 'false') { return false; } else { return value; }
// const keys = path.split('.'); } else { return value; }
}
// keys.reduce((acc, key, index) => {
// if (index === keys.length - 1) {
// delete acc[key];
// return true;
// }
// return acc[key];
// }, _obj);
// return _obj;
// }
updateValue(obj, value, path) { updateValue(obj, value, path) {
let i; let i;