Skip to content
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
31 changes: 18 additions & 13 deletions lib/core/src/lib/form/components/form-renderer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,24 @@
<div
class="adf-grid-list-container"
[class.adf-grid-list-container-multiple]="hasMultipleRows"
>
<h4 class="adf-grid-list-container-label">{{ 'FORM.FORM_RENDERER.ROW_LABEL' | translate: {number: rowIndex + 1} }}</h4>
[class.adf-grid-list-container-disabled]="currentRootElement.field.readOnly"
>
<div class="adf-grid-list-row">
<span class="adf-grid-list-row-label">{{ 'FORM.FORM_RENDERER.ROW_LABEL' | translate: {number: rowIndex + 1} }}</span>

@let shouldDisplayRemoveRowButton = !currentRootElement.field.rows[rowIndex].isInitial || (currentRootElement.field.rows[rowIndex].isInitial && currentRootElement.field.params.allowInitialRowsDelete);
@if (shouldDisplayRemoveRowButton) {
<button
mat-icon-button
class="adf-grid-list-row-remove-button"
[disabled]="currentRootElement.field.readOnly"
[matTooltip]="'FORM.FORM_RENDERER.DELETE_ROW' | translate"
(click)="displayDialogToRemoveRow(currentRootElement.field, rowIndex)"
>
<mat-icon>close</mat-icon>
</button>
}
</div>
<section class="adf-grid-list-column-view">
@for (column of row.columns; track $index) {
<div
Expand All @@ -100,17 +116,6 @@ <h4 class="adf-grid-list-container-label">{{ 'FORM.FORM_RENDERER.ROW_LABEL' | tr
}
</div>
}

@let shouldDisplayRemoveRowButton = !currentRootElement.field.rows[rowIndex].isInitial || (currentRootElement.field.rows[rowIndex].isInitial && currentRootElement.field.params.allowInitialRowsDelete);
@if (shouldDisplayRemoveRowButton) {
<button
mat-icon-button
class="adf-grid-list-remove-row-button"
(click)="displayDialogToRemoveRow(currentRootElement.field, rowIndex)"
>
<mat-icon>close</mat-icon>
</button>
}
</section>
</div>
}
Expand Down
42 changes: 31 additions & 11 deletions lib/core/src/lib/form/components/form-renderer.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,48 @@
padding-right: 3px;
}

&-remove-row-button {
margin-top: 20px;

#{ms.$mat-icon} {
&-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;

&-remove-button {
padding: 0;
width: 30px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
justify-content: center;

#{ms.$mat-icon} {
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
}
}
}

&-container {
padding: 0 10px;

&-label {
margin: 5px 0 5px -10px;
}
padding: 0 15px;

&-multiple {
border-bottom: 1px solid rgba(0, 0, 0, 0.54);
margin-bottom: 25px;
}

&-disabled {
&.adf-grid-list-container-multiple {
border-bottom: 1px solid
var(--mdc-text-button-disabled-label-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent));
}

.adf-grid-list-row-label {
color: var(--mdc-text-button-disabled-label-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent));
cursor: default;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ describe('Form Renderer Component', () => {
expect(row).toBeTruthy();

const removeRowButton = testingUtils.getByCSS(
'#field-RepeatableSection0tbw2y-container .adf-grid-list-container .adf-grid-list-remove-row-button'
'#field-RepeatableSection0tbw2y-container .adf-grid-list-container .adf-grid-list-row-remove-button'
);

expect(removeRowButton).toBeTruthy();
Expand All @@ -938,7 +938,7 @@ describe('Form Renderer Component', () => {
expect(row).toBeTruthy();

const removeRowButton = testingUtils.getByCSS(
'#field-RepeatableSection0tbw2y-container .adf-grid-list-container .adf-grid-list-remove-row-button'
'#field-RepeatableSection0tbw2y-container .adf-grid-list-container .adf-grid-list-row-remove-button'
);

expect(removeRowButton).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { FormSectionComponent } from './form-section/form-section.component';
import { DecimalRenderMiddlewareService } from './middlewares/decimal-middleware.service';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '../../../lib/dialogs/confirm-dialog/confirm.dialog';
import { MatTooltipModule } from '@angular/material/tooltip';

@Component({
selector: 'adf-form-renderer',
Expand Down Expand Up @@ -63,7 +64,8 @@ import { ConfirmDialogComponent } from '../../../lib/dialogs/confirm-dialog/conf
NgClass,
HeaderWidgetComponent,
FormSectionComponent,
RepeatWidgetComponent
RepeatWidgetComponent,
MatTooltipModule
],
encapsulation: ViewEncapsulation.None
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,61 +1272,121 @@ describe('FormFieldModel', () => {
let form: FormModel;
let field: FormFieldModel;

const fields = {
'1': [
{
id: 'Text0wwp7n',
name: 'Text',
type: 'text',
readOnly: false,
required: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
],
'2': [
{
id: 'Integer0rzkwq',
name: 'Integer',
type: 'integer',
readOnly: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minValue: null,
maxValue: null,
required: false,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
]
};

const fieldsDisabled = {
'1': [
{
id: 'Text0wwp7n',
name: 'Text',
type: 'text',
readOnly: true,
required: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
],
'2': [
{
id: 'Integer0rzkwq',
name: 'Integer',
type: 'integer',
readOnly: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minValue: null,
maxValue: null,
required: false,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
]
};

const json = {
id: 'RepeatableSection0tbw2y',
name: 'Repeatable Section',
type: 'repeatable-section',
tab: null,
params: {
initialNumberOfRows: 2,
allowInitialRowsDelete: true,
maxNumberOfRows: 5
},
numberOfColumns: 2,
fields
};

const jsonDisabled = {
id: 'RepeatableSection0tbw2y',
name: 'Repeatable Section',
type: 'repeatable-section',
tab: null,
params: {
initialNumberOfRows: 2,
allowInitialRowsDelete: true,
maxNumberOfRows: 5
},
numberOfColumns: 2,
fields: fieldsDisabled
};

beforeEach(() => {
form = new FormModel();
field = new FormFieldModel(form, {
id: 'RepeatableSection0tbw2y',
name: 'Repeatable Section',
type: 'repeatable-section',
tab: null,
params: {
initialNumberOfRows: 2,
allowInitialRowsDelete: true,
newRowsLimit: 3
},
numberOfColumns: 2,
fields: {
'1': [
{
id: 'Text0wwp7n',
name: 'Text',
type: 'text',
readOnly: false,
required: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
],
'2': [
{
id: 'Integer0rzkwq',
name: 'Integer',
type: 'integer',
readOnly: false,
colspan: 1,
rowspan: 1,
placeholder: null,
minValue: null,
maxValue: null,
required: false,
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
}
}
]
}
});
field = new FormFieldModel(form, json);
});

describe('add row', () => {
Expand Down Expand Up @@ -1408,5 +1468,64 @@ describe('FormFieldModel', () => {
expect(form.values[field.id]).toEqual(formValues.removeState);
});
});

describe('disabled state', () => {
const textWidgetId = 'Text0wwp7n';

/**
*
* @param expectation expectation function
*/
function checkChildrenWidgets(expectation: any) {
for (const row of field.rows) {
for (const column of row.columns) {
for (const child of column.fields) {
expectation(child);
}
}
}
}
it('should make all children fields disabled if repeatable section is disabled', () => {
field.readOnly = true;

checkChildrenWidgets((child) => {
expect(child.readOnly).toBeTruthy();
});
});

it('should allow for initial disabled children widgets if repeatable section is enabled', () => {
field = new FormFieldModel(form, jsonDisabled);

checkChildrenWidgets((child) => {
if (child.id.startsWith(textWidgetId)) {
expect(child.readOnly).toBeTruthy();
return;
}

expect(child.readOnly).toBeFalsy();
});
});

it('should keep initial disabled children widgets if repeatable section is re-enabled', () => {
field = new FormFieldModel(form, jsonDisabled);
field.rows[0].columns[0].fields[0].readOnly = true;
field.readOnly = true;

checkChildrenWidgets((child) => {
expect(child.readOnly).toBeTruthy();
});

field.readOnly = false;

checkChildrenWidgets((child) => {
if (child.id.startsWith(textWidgetId)) {
expect(child.readOnly).toBeTruthy();
return;
}

expect(child.readOnly).toBeFalsy();
});
});
});
});
});
Loading
Loading