Skip to content

Commit

Permalink
Merge pull request #142 from formio/FIO-8901-fix-nested-array-model
Browse files Browse the repository at this point in the history
FIO-8901: Fixed incorrect handling of excessive rows in nested array model
  • Loading branch information
lane-formio authored Aug 27, 2024
2 parents 27c9e8c + 6d147db commit ac66b9b
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 ac66b9b

Please sign in to comment.