Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-30066 Render sections in form builder #10552

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
*ngFor="let column of currentRootElement?.columns"
[style.width.%]="getColumnWith(currentRootElement)">
<div class="adf-grid-list-column-view-item" *ngFor="let field of column?.fields">
<adf-form-field *ngIf="field" [field]="field" />
<ng-container *ngIf="field.type === 'section'; else formField">
to be implemented
</ng-container>
<ng-template #formField>
<adf-form-field [field]="field" />
</ng-template>
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,23 +59,27 @@ 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);
}

static isReactiveType(type: string): boolean {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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));
}
Expand Down
Loading