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-8920 fixed errors list for the form with nested wizard #5801

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
4 changes: 4 additions & 0 deletions src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@ export default class Webform extends NestedDataComponent {
errors = [errors];
}

if (Array.isArray(this.errors)) {
errors = _.union(errors, this.errors);
}
Comment on lines +1262 to +1264
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to use native Javascript methods as much as possible. here that would look like:
errors = [...errors, ... this.errors];


errors = errors.concat(this.customErrors).filter((err) => !!err);

if (!errors.length) {
Expand Down
30 changes: 30 additions & 0 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ import formWithNotAllowedTags from '../test/forms/formWithNotAllowedTags';
import formWithValidateWhenHidden from '../test/forms/formWithValidateWhenHidden';
import formWithEditGrid from '../test/forms/formWithEditGrid';
import formWithSelectRadioUrlDataSource from '../test/forms/selectRadioUrlDataSource';
import wizardWithRequiredFields from '../test/forms/wizardWithRequiredFields';
import webformWithNestedWizard from '../test/forms/webformWIthNestedWizard';
const SpySanitize = sinon.spy(FormioUtils, 'sanitize');

if (_.has(Formio, 'Components.setComponents')) {
Expand Down Expand Up @@ -2393,6 +2395,34 @@ describe('Webform tests', function() {
}).catch(done);
});

it('Should display Errors list for the Form with Nested Wizard Form correctly', (done) => {
const formElement = document.createElement('div');
const form = new Webform(formElement);
const nestedWizard = _.cloneDeep(wizardWithRequiredFields);

form.setForm(webformWithNestedWizard).then(() => {
const nestedFormComp = form.getComponent('formNested');
const button = form.getComponent('submit');
nestedFormComp.loadSubForm = ()=> {
nestedFormComp.formObj = nestedWizard;
nestedFormComp.subFormLoading = false;
return new Promise((resolve) => resolve(nestedWizard));
};

nestedFormComp.createSubForm();
setTimeout(() => {
button.emit('submitButton');
setTimeout(() => {
assert(button.refs.button.className.includes('btn-danger submit-fail'));
assert.equal(form.errors.length, 4);
assert.equal(form.refs.errorRef.length, 4);
done();
}, 100);
},500)
})
.catch((err) => done(err));
});

it('Should set calculated value correctly', (done) => {
formElement.innerHTML = '';
const form = new Webform(formElement);
Expand Down
53 changes: 53 additions & 0 deletions test/forms/webformWIthNestedWizard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export default {
type: 'form',
components: [
{
label: 'Parent Text',
tableView: true,
validate: {
required: true
},
key: 'parentText',
type: 'textfield',
input: true
},
{
label: 'Parent Number',
mask: false,
spellcheck: true,
tableView: false,
delimiter: false,
requireDecimal: false,
inputFormat: 'plain',
validate: {
required: true
},
key: 'parentNumber',
type: 'number',
input: true
},
{
label: 'Form Nested',
tableView: true,
useOriginalRevision: false,
key: 'formNested',
type: 'form',
input: true
},
{
label: 'Submit',
showValidations: false,
tableView: false,
key: 'submit',
type: 'button',
input: true,
saveOnEnter: false
}
],
revisions: '',
_vid: 0,
title: 'webform with nested wizard',
display: 'form',
name: 'webformWithNestedWizard',
path: 'webformwithnestedwizard'
};
Loading