From 1d6d8a941a70b6fe4136c5a5cfa61d82fc5b1a9b Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Tue, 10 Sep 2024 11:45:30 +0300 Subject: [PATCH 1/2] FIO-8920 fixed errors list for the form with nested wizard --- src/Webform.js | 5 +++ src/Webform.unit.js | 30 +++++++++++++++ test/forms/webformWIthNestedWizard.js | 53 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 test/forms/webformWIthNestedWizard.js diff --git a/src/Webform.js b/src/Webform.js index 660ee6cee4..8d9d585784 100644 --- a/src/Webform.js +++ b/src/Webform.js @@ -1259,6 +1259,10 @@ export default class Webform extends NestedDataComponent { errors = [errors]; } + if (Array.isArray(this.errors)) { + errors = _.union(errors, this.errors); + } + errors = errors.concat(this.customErrors).filter((err) => !!err); if (!errors.length) { @@ -1388,6 +1392,7 @@ export default class Webform extends NestedDataComponent { * @returns {Array} errors - All errors. */ onSubmissionError(error) { + // console.log(error, ' - error in onSubmissionError') error = this.normalizeError(error); this.submitting = false; diff --git a/src/Webform.unit.js b/src/Webform.unit.js index 2c6b0ecb57..6c46d33bde 100644 --- a/src/Webform.unit.js +++ b/src/Webform.unit.js @@ -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')) { @@ -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); diff --git a/test/forms/webformWIthNestedWizard.js b/test/forms/webformWIthNestedWizard.js new file mode 100644 index 0000000000..1b0d1857eb --- /dev/null +++ b/test/forms/webformWIthNestedWizard.js @@ -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' +}; From effff2f00c477d154fe6176f3d51b80e1a331cce Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Tue, 10 Sep 2024 11:53:46 +0300 Subject: [PATCH 2/2] FIO-8920 removing console.log --- src/Webform.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Webform.js b/src/Webform.js index 8d9d585784..1aaca0de58 100644 --- a/src/Webform.js +++ b/src/Webform.js @@ -1392,7 +1392,6 @@ export default class Webform extends NestedDataComponent { * @returns {Array} errors - All errors. */ onSubmissionError(error) { - // console.log(error, ' - error in onSubmissionError') error = this.normalizeError(error); this.submitting = false;