Skip to content

Commit

Permalink
FIO-8724: fixed firing change event for DataGrid component
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-formio committed Dec 3, 2024
1 parent 82dc938 commit 606556f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/components/datagrid/DataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export default class DataGridComponent extends NestedArrayComponent {
});
this.checkConditions();
this.triggerChange();
this.triggerChange({ modified: true });
this.redraw().then(() => {
this.focusOnNewRowElement(this.rows[index]);
});
Expand Down Expand Up @@ -578,6 +579,9 @@ export default class DataGridComponent extends NestedArrayComponent {
const options = _.clone(this.options);
options.name += `[${rowIndex}]`;
options.row = `${rowIndex}-${colIndex}`;
options.onChange = (flags, changed, modified) => {
this.triggerChange({ modified });
}

let columnComponent;

Expand Down
91 changes: 89 additions & 2 deletions test/unit/DataGrid.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('DataGrid Component', () => {
done();
}).catch(done);
}, 300);
}, 300);
}, 350);
}, 300);
}, 300);
})
Expand Down Expand Up @@ -525,6 +525,93 @@ describe('DataGrid Component', () => {
}, 300);
}).catch((err) => done(err));
});

it('Should trigger DataGrid change event when row component value changes', (done) => {
Formio.createForm(document.createElement('div'), {
type: 'form',
display: 'form',
components: [{
label: 'Datagrid',
key: 'dataGrid',
type: 'datagrid',
defaultValue: [{ }],
input: true,
components: [
{
label: 'Number',
key: 'number',
type: 'number',
input: true
},
],
}],
}).then((form) => {
form.on('change', ({ changed }) => {
assert(changed.component.key, 'dataGrid');
done();
});
const numberComp = form.getComponent(['dataGrid', 0, 'number']);
numberComp.setValue(1);
}).catch((err) => done(err));
});

it('Should trigger DataGrid change event when adding a new row', (done) => {
Formio.createForm(document.createElement('div'), {
type: 'form',
display: 'form',
components: [{
label: 'Datagrid',
key: 'dataGrid',
type: 'datagrid',
defaultValue: [{ }],
input: true,
components: [
{
label: 'Number',
key: 'number',
type: 'number',
input: true
},
],
}],
}).then((form) => {
form.on('change', ({ changed }) => {
assert(changed.component.key, 'dataGrid');
done();
});
const dataGrid = form.getComponent(['dataGrid']);
dataGrid.addRow();
}).catch((err) => done(err));
});

it('Should trigger DataGrid change event when removing the row', (done) => {
Formio.createForm(document.createElement('div'), {
type: 'form',
display: 'form',
components: [{
label: 'Datagrid',
key: 'dataGrid',
type: 'datagrid',
defaultValue: [{ }],
input: true,
components: [
{
label: 'Number',
key: 'number',
type: 'number',
input: true
},
],
}],
}).then((form) => {
form.on('change', ({ changed }) => {
assert(changed.component.key, 'dataGrid');
done();
});
const dataGrid = form.getComponent(['dataGrid']);
dataGrid.removeRow(0);
}).catch((err) => done(err));
});
});

describe('DataGrid Panels', () => {
Expand Down Expand Up @@ -971,7 +1058,7 @@ describe('SaveDraft functionality', () => {
{
saveDraft: true,
skipDraftRestore: true,
saveDraftThrottle: 100
saveDraftThrottle: 300
}
).then((form) => {
setTimeout(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ describe('Webform tests', function() {
done();
}, 300);
}, 300);
}, 300);
}, 450);
}).catch((err) => done(err));
});

Expand Down Expand Up @@ -3717,7 +3717,7 @@ describe('Webform tests', function() {
assert.equal(radio.dataValue, calculatedValues.radio);
document.body.innerHTML = '';
done();
}, 300);
}, 350);
}, 300);
}, 300);
}, 300);
Expand Down

0 comments on commit 606556f

Please sign in to comment.