diff --git a/projects/rero/ng-core/src/lib/record/editor/fieldset/fieldset.component.ts b/projects/rero/ng-core/src/lib/record/editor/fieldset/fieldset.component.ts
index f1c93af8..9d88db7b 100644
--- a/projects/rero/ng-core/src/lib/record/editor/fieldset/fieldset.component.ts
+++ b/projects/rero/ng-core/src/lib/record/editor/fieldset/fieldset.component.ts
@@ -172,6 +172,7 @@ export class FieldsetComponent implements OnInit {
}
for (const item of field.items) {
this.resetFormGroup(item);
+ this.disableFormGroup(item);
}
}
@@ -186,4 +187,17 @@ export class FieldsetComponent implements OnInit {
control.reset();
return true;
}
+
+ /**
+ * Mark a layoutNode FormControl as disabled.
+ * @param layoutNode - object, angular6 json schema form layout node
+ */
+ private disableFormGroup(layoutNode) {
+ const control = getControl(this.jsf.formGroup, layoutNode.dataPointer);
+ if (!control) {
+ return false;
+ }
+ control.disable();
+ return true;
+ }
}
diff --git a/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.html b/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.html
index c8964a5e..2deb6828 100644
--- a/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.html
+++ b/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.html
@@ -16,8 +16,8 @@
-->
-
New
-
diff --git a/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.ts b/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.ts
index 50bf5899..80732db7 100644
--- a/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.ts
+++ b/projects/rero/ng-core/src/lib/record/editor/main-fields-manager/main-fields-manager.component.ts
@@ -16,7 +16,7 @@
*/
import { Component, OnInit } from '@angular/core';
-import { JsonSchemaFormService, forEach } from 'angular6-json-schema-form';
+import { JsonSchemaFormService, forEach, getControl } from 'angular6-json-schema-form';
@Component({
selector: 'ng-core-main-fields-manager',
@@ -25,11 +25,17 @@ import { JsonSchemaFormService, forEach } from 'angular6-json-schema-form';
})
export class MainFieldsManagerComponent implements OnInit {
// ref to field to show/hide given the key element
- private layoutRefField = {};
- constructor(
- private jsf: JsonSchemaFormService
- ) { }
+ private layoutRefField: any = {};
+ /**
+ * Constructor
+ * @param jsf: angular6 jsonschema form service
+ */
+ constructor(private jsf: JsonSchemaFormService) { }
+
+ /**
+ * Component initialisation.
+ */
ngOnInit() {
// keep in cache a dict with the field key name as a key and the layoutNode as a value
let fieldToShow;
@@ -70,14 +76,67 @@ export class MainFieldsManagerComponent implements OnInit {
field.options.show = true;
}
}
+ // disable FormControls for hidden fields
+ for (const fieldSet of Object.values(this.layoutRefField)) {
+ if (this.isHidden(fieldSet)) {
+ for (const field of fieldSet['items']) {
+ this.disableFormGroup(field);
+ }
+ }
+ }
}
- get fieldsToShow() {
- return this.jsf.layout.filter(item => 'show' in item.options && item.options.show === false);
+ /**
+ * Return the list of the hidden form layout.
+ * @param formLayout - object, angular6 json schema form layout
+ */
+ get hiddenFields() {
+ return this.jsf.layout.filter(layout => this.isHidden(layout) );
}
- show(field) {
- field.options.show = true;
+ /**
+ * Compute the visibility of a given formLayout.
+ * @param formLayout - object, angular6 json schema form layout
+ */
+ isHidden(formLayout) {
+ return 'show' in formLayout.options && formLayout.options.show === false;
+ }
+
+ /**
+ * Show a given fieldset.
+ * @param formLayout - object, angular6 json schema form layout
+ */
+ show(formLayout) {
+ formLayout.options.show = true;
+ for (const item of formLayout.items) {
+ this.enableFormGroup(item);
+ }
+ }
+
+ /**
+ * Mark a layoutNode FormControl as enabled.
+ * @param layoutNode - object, angular6 json schema form layout node
+ */
+ private enableFormGroup(layoutNode) {
+ const control = getControl(this.jsf.formGroup, layoutNode.dataPointer);
+ if (!control) {
+ return false;
+ }
+ control.enable();
+ return true;
+ }
+
+ /**
+ * Mark a layoutNode FormControl as disabled.
+ * @param layoutNode - object, angular6 json schema form layout node
+ */
+ private disableFormGroup(layoutNode) {
+ const control = getControl(this.jsf.formGroup, layoutNode.dataPointer);
+ if (!control) {
+ return false;
+ }
+ control.disable();
+ return true;
}
}