Skip to content

Commit

Permalink
FIO-3703: Fixes an issue where NestedData components with modal view …
Browse files Browse the repository at this point in the history
…do not render values inside Layout components in modal preview table
  • Loading branch information
alexandraRamanenka committed Apr 8, 2024
1 parent b58c530 commit 77d7e75
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class NestedArrayComponent extends NestedDataComponent {
}

getComponents(rowIndex) {
if (rowIndex !== undefined) {
if (rowIndex !== undefined && rowIndex !== null) {
if (!this.iteratableRows[rowIndex]) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/_classes/nesteddata/NestedDataComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class NestedDataComponent extends NestedComponent {

const htmlTagRegExp = new RegExp('<(.*?)>');

this.components.forEach((component) => {
this.everyComponent((component) => {
if (component.isInputComponent && component.visible && !component.skipInEmail) {
const componentValue = component.getView(component.dataValue, options);
result += (`
Expand Down
30 changes: 29 additions & 1 deletion src/components/_classes/nesteddata/NestedDataComponent.unit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';
import { Formio } from '../../../Formio';
import NestedDataComponent from './NestedDataComponent';
import Harness from '../../../../test/harness';
import assert from 'power-assert';
import nestedDataCompWithModalPreview from '../../../../test/forms/nestedDataWithModalViewAndLayoutComponents';

let component = null;
describe('NestedDataComponent class', () => {
it('Should create a new NestedDataComponent class', () => {
it('Should create a new NestedDataComponent class', (done) => {

Check warning on line 10 in src/components/_classes/nesteddata/NestedDataComponent.unit.js

View workflow job for this annotation

GitHub Actions / setup

'done' is defined but never used
return Harness.testCreate(NestedDataComponent, {
// key: 'nested',
components: [
Expand All @@ -25,4 +28,29 @@ describe('NestedDataComponent class', () => {
Harness.testElements(component, 'input[name="data[lastName]"]', 1);
});
});
it('Should show preview of the modal view component properly', () => {
Formio.createForm(document.createElement('div'), nestedDataCompWithModalPreview)
.then((form) => {
const openModalBtn = form.element.querySelector('.open-modal-button');
const openModalBtnRows = openModalBtn.querySelectorAll('tr');
assert.equal(openModalBtnRows.length, 1);

const dataGrid = form.geComponent(['dataGrid']);
dataGrid.setValue([
{
textField: 'test'
},
{
textField: 'test2'
}
]);

setTimeout(() => {
const modalPreviewValues = form.element.querySelector('.open-modal-button tr td input');
assert.equal(modalPreviewValues.length, 2);
assert.deepEqual(Array.prototype.map.call(modalPreviewValues, (i) => i.value), ['test', 'test2']);
done();

Check failure on line 52 in src/components/_classes/nesteddata/NestedDataComponent.unit.js

View workflow job for this annotation

GitHub Actions / setup

'done' is not defined
}, 300);
}).catch(done);

Check failure on line 54 in src/components/_classes/nesteddata/NestedDataComponent.unit.js

View workflow job for this annotation

GitHub Actions / setup

'done' is not defined
});
});
54 changes: 54 additions & 0 deletions test/forms/nestedDataWithModalViewAndLayoutComponents
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "fio3703",
"path": "fio3703",
"type": "form",
"display": "form",
"components": [
{
"label": "Data Grid",
"reorder": false,
"addAnotherPosition": "bottom",
"layoutFixed": false,
"enableRowGroups": false,
"initEmpty": false,
"tableView": true,
"modalEdit": true,
"defaultValue": [
{
"textField": ""
}
],
"key": "dataGrid",
"type": "datagrid",
"input": true,
"components": [
{
"collapsible": false,
"key": "panel",
"type": "panel",
"label": "Panel",
"input": false,
"tableView": false,
"components": [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"key": "textField",
"type": "textfield",
"input": true
}
]
}
]
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
],
}

0 comments on commit 77d7e75

Please sign in to comment.