From 0e19f53068aa0e8b996cf690d77c279ceae125ca Mon Sep 17 00:00:00 2001
From: Tomasz Gnyp <49343696+tomgny@users.noreply.github.com>
Date: Tue, 14 Jan 2025 12:50:49 +0100
Subject: [PATCH] AAE-30066 Render sections in form builder (#10552)
* AAE-30066 Render sections in runtime
* added unit tests
* remove comment
* added return type to method
* added self closing tag
---
.../components/form-renderer.component.html | 7 ++++-
.../widgets/core/form-field-types.ts | 13 ++++++---
.../widgets/core/form-field.model.spec.ts | 29 ++++++++++++++++++-
.../widgets/core/form-field.model.ts | 8 +++--
4 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/lib/core/src/lib/form/components/form-renderer.component.html b/lib/core/src/lib/form/components/form-renderer.component.html
index 706b27c578..18f65a016b 100644
--- a/lib/core/src/lib/form/components/form-renderer.component.html
+++ b/lib/core/src/lib/form/components/form-renderer.component.html
@@ -40,7 +40,12 @@
*ngFor="let column of currentRootElement?.columns"
[style.width.%]="getColumnWith(currentRootElement)">
-
+
+ to be implemented
+
+
+
+
diff --git a/lib/core/src/lib/form/components/widgets/core/form-field-types.ts b/lib/core/src/lib/form/components/widgets/core/form-field-types.ts
index 3bda51016d..a5384a0a1d 100644
--- a/lib/core/src/lib/form/components/widgets/core/form-field-types.ts
+++ b/lib/core/src/lib/form/components/widgets/core/form-field-types.ts
@@ -20,6 +20,7 @@
export class FormFieldTypes {
static CONTAINER: string = 'container';
static GROUP: string = 'group';
+ static SECTION: string = 'section';
static DYNAMIC_TABLE: string = 'dynamic-table';
static TEXT: string = 'text';
static STRING: string = 'string';
@@ -58,11 +59,11 @@ export class FormFieldTypes {
static CONSTANT_VALUE_TYPES: string[] = [FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY];
- static isReadOnlyType(type: string) {
+ static isReadOnlyType(type: string): boolean {
return FormFieldTypes.READONLY_TYPES.includes(type);
}
- static isValidatableType(type: string) {
+ static isValidatableType(type: string): boolean {
return FormFieldTypes.VALIDATABLE_TYPES.includes(type);
}
@@ -70,11 +71,15 @@ export class FormFieldTypes {
return FormFieldTypes.REACTIVE_TYPES.includes(type);
}
- static isConstantValueType(type: string) {
+ static isConstantValueType(type: string): boolean {
return FormFieldTypes.CONSTANT_VALUE_TYPES.includes(type);
}
- static isContainerType(type: string) {
+ static isContainerType(type: string): boolean {
return type === FormFieldTypes.CONTAINER || type === FormFieldTypes.GROUP;
}
+
+ static isSectionType(type: string): boolean {
+ return type === FormFieldTypes.SECTION;
+ }
}
diff --git a/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts b/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts
index 8b6eaa6ba3..036325c043 100644
--- a/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts
+++ b/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts
@@ -869,6 +869,16 @@ describe('FormFieldModel', () => {
expect(field.numberOfColumns).toBe(999);
});
+ it('should calculate the columns in case of section type', () => {
+ const form = new FormModel();
+ const field = new FormFieldModel(form, {
+ type: FormFieldTypes.SECTION,
+ numberOfColumns: 123
+ });
+
+ expect(field.numberOfColumns).toBe(123);
+ });
+
it('should instantiate FormField when has no variable', () => {
const form = new FormModel({});
form.json = {
@@ -890,7 +900,24 @@ describe('FormFieldModel', () => {
readOnly: true
});
field.updateForm();
- expect(form.values['header_field']).not.toBeDefined();
+
+ expect(form.values['header_field']).toBeUndefined();
+ });
+
+ it('section field type should not appear into form values', () => {
+ const form = new FormModel();
+ const field = new FormFieldModel(form, {
+ fieldType: 'SectionFieldtype',
+ id: 'section_field',
+ name: 'section',
+ type: FormFieldTypes.SECTION,
+ value: '',
+ required: false,
+ readOnly: true
+ });
+ field.updateForm();
+
+ expect(form.values['section_field']).toBeUndefined();
});
describe('dropdown field', () => {
diff --git a/lib/core/src/lib/form/components/widgets/core/form-field.model.ts b/lib/core/src/lib/form/components/widgets/core/form-field.model.ts
index 463d044d24..feb28052eb 100644
--- a/lib/core/src/lib/form/components/widgets/core/form-field.model.ts
+++ b/lib/core/src/lib/form/components/widgets/core/form-field.model.ts
@@ -234,7 +234,7 @@ export class FormFieldModel extends FormWidgetModel {
}
}
- if (FormFieldTypes.isContainerType(this.type)) {
+ if (FormFieldTypes.isContainerType(this.type) || FormFieldTypes.isSectionType(this.type)) {
this.containerFactory(json, form);
}
}
@@ -526,7 +526,7 @@ export class FormFieldModel extends FormWidgetModel {
break;
}
default:
- if (!FormFieldTypes.isReadOnlyType(this.type) && !this.isInvalidFieldType(this.type)) {
+ if (this.shouldUpdateFormValues(this.type)) {
this.form.values[this.id] = this.value;
}
}
@@ -557,6 +557,10 @@ export class FormFieldModel extends FormWidgetModel {
return this.hasEmptyValue && option?.id === this.defaultEmptyOptionId;
}
+ private shouldUpdateFormValues(type): boolean {
+ return !FormFieldTypes.isReadOnlyType(type) && !this.isInvalidFieldType(type) && !FormFieldTypes.isSectionType(type);
+ }
+
private addOptions(options: FormFieldOption[]) {
options.forEach((option) => this.addOption(option));
}