Skip to content

Commit c32a477

Browse files
[DURACOM-444] adapt inline-group parser, style, improve error handling and status reset of form
1 parent 4f6242a commit c32a477

15 files changed

Lines changed: 151 additions & 27 deletions

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function (config) {
1515
],
1616
client: {
1717
clearContext: false, // leave Jasmine Spec Runner output visible in browser
18-
captureConsole: false,
18+
captureConsole: true,
1919
jasmine: {
2020
failSpecWithNoExpectations: true
2121
}

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<ng-container #componentViewContainer></ng-container>
2020
</div>
2121

22-
@if (hasHint && (formBuilderService.hasArrayGroupValue(model) || (!model.repeatable && (isRelationship === false || value?.value === null)) || (model.repeatable === true && context?.index === context?.context?.groups?.length - 1)) && (!showErrorMessages || errorMessages.length === 0)) {
22+
@if (hasHint && (formBuilderService.hasArrayGroupValue(model) || ((!model.repeatable && (!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1)) && (isRelationship === false || value?.value === null)) || (model.repeatable === true && context?.index === context?.context?.groups?.length - 1)) && (!showErrorMessages || errorMessages.length === 0)) {
2323
<small
2424
class="text-muted ds-hint" [innerHTML]="model.hint | translate" [ngClass]="getClass('element', 'hint')"></small>
2525
}
@@ -28,7 +28,7 @@
2828
<div class="clearfix w-100 mb-2"></div>
2929
}
3030

31-
@if (!model.hideErrorMessages && showErrorMessages) {
31+
@if (!model.hideErrorMessages && showErrorMessages && (!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1) && isNotRequiredGroupAndEmpty()) {
3232
<div [id]="id + '_errors'"
3333
[ngClass]="[getClass('element', 'errors'), getClass('grid', 'errors')]">
3434
@for (message of errorMessages; track message) {

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,22 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
461461
this.subs.push(collection$.subscribe((collection) => this.collection = collection));
462462

463463
}
464+
465+
isNotRequiredGroupAndEmpty(): boolean {
466+
const parent = this.model.parent;
467+
// Check if the model is part of a group, the group needs to be an inner form and be in the submission form not in a nested form.
468+
// The check hasValue(parent.parent) tells if the parent is in the submission or in a modal (nested cases)
469+
if (hasValue(parent) && parent.type === 'GROUP' && this.model.isModelOfInnerForm && hasValue(parent.parent)) {
470+
471+
const groupHasSomeValue = parent.group.some(elem => !!elem.value);
472+
473+
if (!groupHasSomeValue && !parent.isRequired && parent.group?.length > 1) {
474+
this.group.reset();
475+
}
476+
477+
return (groupHasSomeValue && !parent.isRequired) || (hasValue(parent.isRequired) && parent.isRequired);
478+
} else {
479+
return true;
480+
}
481+
}
464482
}

src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@
8080
background-color: var(--bs-gray-400);
8181
}
8282
}
83+
84+
85+
.grey-background{
86+
background-color: #f3f3f3;
87+
margin-bottom: 10px;
88+
padding-top: 10px;
89+
margin-left: -1rem;
90+
margin-right: -1rem;
91+
padding-right: 0px;
92+
}

src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
120120
* If the drag feature is disabled for this DynamicRowArrayModel.
121121
*/
122122
get dragDisabled(): boolean {
123-
return this.model.groups.length === 1 || !this.model.isDraggable;
123+
return this.model.groups.length === 1 || !this.model.isDraggable || this.model.notRepeatable;
124124
}
125125

126126
/**

src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export class DynamicRelationGroupModel extends DsDynamicInputModel {
5353
this.scopeUUID = config.scopeUUID;
5454
this.submissionScope = config.submissionScope;
5555
this.isInlineGroup = config.isInlineGroup;
56-
const value = config.value || [];
57-
this.value = value;
56+
this.value = config.value || [];
5857
}
5958

6059
/* get value() {

src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-inline-group/dynamic-relation-inline-group.components.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ export class DsDynamicRelationInlineGroupComponent extends DynamicFormControlCom
273273

274274
private copyArrayItem(event) {
275275
const index = Array.isArray(this.model.value) ? this.model.value.length : event.model.parent.index;
276-
const mainRow = event.model.group.find(itemModel => itemModel.name === this.model.name);
277276
const groupValue = this.getRowValue(event.model as DynamicFormGroupModel);
278277
this.updateArrayModelValue(groupValue, index);
279278
this.change.emit();

src/app/shared/form/builder/parsers/field-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export abstract class FieldParser {
128128

129129
const layout: DynamicFormControlLayout = {
130130
grid: {
131-
group: 'row',
131+
group: 'form-row',
132132
},
133133
};
134134

@@ -400,6 +400,7 @@ export abstract class FieldParser {
400400

401401
protected markAsNotRepeatable(controlModel) {
402402
controlModel.isModelOfNotRepeatableGroup = true;
403+
controlModel.repeatable = false;
403404

404405
controlModel.errorMessages = Object.assign(
405406
{},

src/app/shared/form/form.component.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,45 @@
1515
<!--Array with repeatable items-->
1616
@if ((!context.notRepeatable) && !isVirtual(context, index) && group.context.groups.length !== 1 && !isItemReadOnly(context, index)) {
1717
<div
18+
[class.isInlineGroupForm-delete]="isInlineGroupForm"
19+
[ngClass]="{'justify-content-sm-end' : isInlineGroupForm }"
1820
class="col-2 d-flex flex-column justify-content-sm-start align-items-end">
1921
<button type="button" class="btn btn-secondary" role="button"
2022
title="{{'form.remove' | translate}}"
2123
[attr.aria-label]="'form.remove' | translate"
2224
(click)="removeItem($event, context, index)">
2325
<span><i class="fas fa-trash" aria-hidden="true"></i></span>
2426
</button>
27+
@if (isInlineGroupForm) {
28+
<div class="clearfix w-100 mb-2"></div>
29+
}
2530
</div>
2631
}
32+
@if ((!context.notRepeatable) && isInlineGroupForm) {
33+
<div class="clearfix w-100">
34+
<div class="btn-group" role="group" aria-label="remove button">
35+
<button type="button" role="button" class="ds-form-add-more btn btn-link"
36+
title="{{'form.copy' | translate}}"
37+
attr.aria-label="{{'form.copy' | translate}}"
38+
[dsBtnDisabled]="isItemReadOnly(context, index)"
39+
(click)="copyItem($event, group.context, index)">
40+
<span><i class="fas fa-copy"></i> {{'form.copy' | translate}}</span>
41+
</button>
42+
</div>
43+
</div>
44+
}
45+
46+
2747
@if ((!context.notRepeatable) && index === (group.context.groups.length - 1) && !isItemReadOnly(context, index)) {
28-
<div class="clearfix ps-4 w-100">
48+
<div class="clearfix w-100"
49+
[class.ps-4]="!isInlineGroupForm"
50+
[class.white-background]="isInlineGroupForm">
2951
<div class="btn-group" role="group">
3052
<button type="button" role="button" class="ds-form-add-more btn btn-link"
3153
title="{{'form.add' | translate}}"
3254
attr.aria-label="{{'form.add' | translate}}"
55+
[class.ps-0]="isInlineGroupForm"
56+
[dsBtnDisabled]="isItemReadOnly(context, index)"
3357
(click)="insertItem($event, group.context, group.context.groups.length)">
3458
<span><i class="fas fa-plus"></i> {{'form.add' | translate}}</span>
3559
</button>
@@ -49,6 +73,10 @@
4973
[dsBtnDisabled]="group.context.groups.length === 1 || isItemReadOnly(context, index)">
5074
<span>{{'form.discard' | translate}}</span>
5175
</button>
76+
@if (isInlineGroupForm) {
77+
<div class="clearfix w-100 mb-2"></div>
78+
}
79+
5280
</div>
5381
</div>
5482
}

src/app/shared/form/form.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ select.form-control {
5656
padding-left: 15px;
5757
padding-right: 15px;
5858
}
59+
60+
.isInlineGroupForm-delete {
61+
margin-bottom: -2.5rem;
62+
z-index: var(--ds-submission-inline-group-form-delete-z-index);
63+
padding-right: calc(0.5 * var(--bs-spacer));
64+
}
65+
66+
.white-background{
67+
background-color: #fff;
68+
}

0 commit comments

Comments
 (0)