Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO 7603 Edit Grid With Empty Rows Not Submitting Form #5496

Merged
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
2 changes: 1 addition & 1 deletion src/components/editgrid/EditGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ export default class EditGridComponent extends NestedArrayComponent {
}
return false;
}
else if (rowsEditing && this.saveEditMode) {
else if (rowsEditing && this.saveEditMode && !this.component.openWhenEmpty) {
this.setCustomValidity(this.t(this.errorMessage('unsavedRowsError')), dirty);
return false;
}
Expand Down
43 changes: 43 additions & 0 deletions src/components/editgrid/EditGrid.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './fixtures';

import ModalEditGrid from '../../../test/forms/modalEditGrid';
import EditGridOpenWhenEmpty from '../../../test/forms/editGridOpenWhenEmpty';
import Webform from '../../Webform';
import { displayAsModalEditGrid } from '../../../test/formtest';
import { Formio } from '../../Formio';
Expand Down Expand Up @@ -1382,4 +1383,46 @@ describe('EditGrid Open when Empty', () => {
})
.catch(done);
});

it('Should submit form with empty rows when submit button is pressed and no rows are saved', (done) => {
const formElement = document.createElement('div');
const form = new Webform(formElement);

form.setForm(compOpenWhenEmpty).then(() => {
const editGrid = form.components[0];

setTimeout(() => {
Harness.dispatchEvent('click', form.element, '[name="data[submit]"]');
setTimeout(() => {
const editRow = editGrid.editRows[0];
assert(!editGrid.error, 'Should be no errors on EditGrid');
assert.equal(editRow.errors, null, 'Should not be any errors on open row');
assert.equal(form.submission.state, 'submitted', 'Form should be submitted');
done();
}, 450);
}, 100);
}).catch(done);
});

it('Should not submit form if any row inputs are set as required', (done) => {
const formElement = document.createElement('div');
const form = new Webform(formElement);

form.setForm(EditGridOpenWhenEmpty).then(() => {
const editGrid = form.components[0];

setTimeout(() => {
Harness.dispatchEvent('click', form.element, '[name="data[submit]"]');
setTimeout(() => {
assert(!form.submission.state, 'Form should not be submitted');
const editRow = editGrid.editRows[0];
assert(editGrid.error, 'Should show error on EditGrid');
assert.equal(editRow.errors.length, 1, 'Should show error on row');
const textField = editRow.components[0];
assert(textField.element.className.includes('formio-error-wrapper'), 'Should add error class to component');
done();
}, 450);
}, 100);
}).catch(done);
});
});
67 changes: 67 additions & 0 deletions test/forms/editGridOpenWhenEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export default {
_id: '65b119c4414257179284c2b4',
type: 'form',
tags: [],
owner: '5e05a6b7549cdc2ece30c6b0',
components: [
{
label: 'Edit Grid',
openWhenEmpty: true,
tableView: false,
rowDrafts: false,
key: 'editGrid',
type: 'editgrid',
input: true,
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
validate: { required: true },
key: 'textField',
type: 'textfield',
input: true
},
{
label: 'Text Area',
applyMaskOn: 'change',
autoExpand: false,
tableView: true,
key: 'textArea',
type: 'textarea',
input: true
}
]
},
{
type: 'button',
label: 'Submit',
key: 'submit',
input: true,
tableView: false,
showValidations: false,
}
],
controller: '',
revisions: '',
_vid: 0,
title: 'Edit Grid',
display: 'form',
access: [
{
roles: [
'5e96e79ee1c3ad3178454100',
'5e96e79ee1c3ad3178454101',
'5e96e79ee1c3ad3178454102'
],
type: 'read_all'
}
],
submissionAccess: [],
settings: {},
properties: {},
name: 'editGrid',
path: 'editgrid',
};


Loading