Skip to content

Commit

Permalink
FIO-8901: fixed incorrect handling of excessive rows in nested array …
Browse files Browse the repository at this point in the history
…model
  • Loading branch information
roma-formio committed Aug 22, 2024
1 parent d596125 commit 6d147db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/experimental/base/array/__tests__/ArrayComponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,32 @@ describe('ArrayComponent', () => {
{
firstName: 'Sally',
lastName: 'Thompson'
},
{
firstName: 'Jane',
lastName: 'Doe'
}
];
arrComp.dataValue = employees;
assert.deepEqual(data, {employees: employees});
assert.deepEqual(arrComp.dataValue, employees);
assert.equal(arrComp.rows.length, 2);
assert.equal(arrComp.rows.length, 3);
assert.equal(arrComp.rows[0].length, 2);
assert.equal(arrComp.rows[1].length, 2);
assert.equal(arrComp.components.length, 4);
assert.equal(arrComp.rows[2].length, 2);
assert.equal(arrComp.components.length, 6);
assert.equal(arrComp.components[0].dataValue, 'Joe');
assert.equal(arrComp.components[1].dataValue, 'Smith');
assert.strictEqual(arrComp.rows[0][0], arrComp.components[0]);
assert.strictEqual(arrComp.rows[0][1], arrComp.components[1]);
assert.strictEqual(arrComp.rows[1][0], arrComp.components[2]);
assert.strictEqual(arrComp.rows[1][1], arrComp.components[3]);
assert.strictEqual(arrComp.rows[2][0], arrComp.components[4]);
assert.strictEqual(arrComp.rows[2][1], arrComp.components[5]);
assert.equal(arrComp.components[2].dataValue, 'Sally');
assert.equal(arrComp.components[3].dataValue, 'Thompson');
assert.equal(arrComp.components[4].dataValue, 'Jane');
assert.equal(arrComp.components[5].dataValue, 'Doe');

// Ensure it removes rows.
employees = [
Expand Down
4 changes: 2 additions & 2 deletions src/experimental/model/NestedArrayModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function NestedArrayModel(props: any = {}) : ModelDecoratorInterface {

// Remove superfluous rows.
if (dataValue.length > value.length) {
for (let i = value.length; i < dataValue.length; i++) {
for (let i = dataValue.length - 1; i >= value.length; i--) {
this.removeRow(i);
}
}
Expand Down Expand Up @@ -192,4 +192,4 @@ export function NestedArrayModel(props: any = {}) : ModelDecoratorInterface {
}
}
}
};
};

0 comments on commit 6d147db

Please sign in to comment.