From 470c0303dabc2fc7c7a94671d2ff0b60e986145b Mon Sep 17 00:00:00 2001 From: alexandraRamanenka <60643585+alexandraRamanenka@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:00:50 +0300 Subject: [PATCH 1/7] =?UTF-8?q?FIO-7206:=20Fixes=20an=20issue=20where=20AP?= =?UTF-8?q?I=20keys=20of=20the=20removed=20components=20are=E2=80=A6=20(#5?= =?UTF-8?q?634)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FIO-7206: Fixes an issue where API keys of the removed components are not removed from the Data Grid defaultValue * Refactoring --- src/WebformBuilder.js | 10 ++++- src/WebformBuilder.unit.js | 77 ++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/WebformBuilder.js b/src/WebformBuilder.js index e6aa69d786..80ad380f5d 100644 --- a/src/WebformBuilder.js +++ b/src/WebformBuilder.js @@ -1131,8 +1131,14 @@ export default class WebformBuilder extends Component { else if (parent.formioComponent && parent.formioComponent.removeChildComponent) { parent.formioComponent.removeChildComponent(component); } - if (component.input && componentInstance && componentInstance.parent) { - _.unset(componentInstance._data, componentInstance.key); + if (component.input && componentInstance && parent.formioComponent) { + const parentDefaultValue = _.get(parent.formioComponent, 'component.defaultValue', null); + if (Array.isArray(parentDefaultValue)) { + parentDefaultValue.forEach(v => _.unset(v, componentInstance.key)); + } + else if (typeof parentDefaultValue === 'object') { + _.unset(parentDefaultValue, componentInstance.key); + } } const rebuild = parent.formioComponent.rebuild() || Promise.resolve(); rebuild.then(() => { diff --git a/src/WebformBuilder.unit.js b/src/WebformBuilder.unit.js index f4ffd0c549..f438f3f850 100644 --- a/src/WebformBuilder.unit.js +++ b/src/WebformBuilder.unit.js @@ -257,40 +257,53 @@ describe('WebformBuilder tests', function() { it('Should remove deleted components keys from default value', (done) => { const builder = Harness.getBuilder(); - builder.setForm({}).then(() => { - Harness.buildComponent('datagrid'); + builder.setForm({ + display: 'form', + type: 'form', + components: [ + { + label: 'Data Grid', + reorder: false, + addAnotherPosition: 'bottom', + layoutFixed: false, + enableRowGroups: false, + initEmpty: false, + tableView: false, + defaultValue: [ + { + textField: '', + }, + ], + validateWhenHidden: false, + key: 'dataGrid', + type: 'datagrid', + input: true, + components: [ + { + label: 'Text Field', + applyMaskOn: 'change', + tableView: true, + validateWhenHidden: false, + key: 'textField', + type: 'textfield', + input: true, + }, + ], + }, + ], + }).then(() => { + const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0]; + textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', { + view: window, + bubbles: true, + cancelable: true + })); setTimeout(() => { - const dataGridDefaultValue = builder.editForm.getComponent('defaultValue'); - dataGridDefaultValue.removeRow(0); - - setTimeout(() => { - Harness.saveComponent(); - setTimeout(() => { - const dataGridContainer = builder.webform.element.querySelector('[ref="dataGrid-container"]'); - Harness.buildComponent('textfield', dataGridContainer); - - setTimeout(() => { - Harness.saveComponent(); - - setTimeout(() => { - const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0]; - textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', { - view: window, - bubbles: true, - cancelable: true - })); - - setTimeout(() => { - const dataGrid = builder.webform.getComponent(['dataGrid']); - assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key'); - done(); - }, 300); - }); - }, 300); - }, 300); - }, 350); - }, 350); + const dataGrid = builder.webform.getComponent(['dataGrid']); + assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key'); + done(); + }, 300); }).catch(done); }); }); From 3ae0d313669249307569b8870fcef59a1af1b267 Mon Sep 17 00:00:00 2001 From: TanyaGashtold <61136841+TanyaGashtold@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:01:52 +0300 Subject: [PATCH 2/7] Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 8d0629e0c6..85752286c8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -255,6 +255,7 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e - FIO-8366: API key is not unique translation - FIO-8433: fixed restore draft for nested forms - FIO-8395: html in error message not evaluating + - FIO-7206: Fixes an issue where API keys of the removed components are not removed from the Data Grid defaultValue ## 5.0.0-rc.37 ### Fixed From 3ceace661790c13bb3f745fd6bfac97379600b32 Mon Sep 17 00:00:00 2001 From: KatrinKhilko <127205485+KatrinKhilko@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:58:05 +0300 Subject: [PATCH 3/7] FIO-8402: fixed an issue where Validation Triggering on initial Form load (#5625) * FIO-8402: fixed an issue where Validation Triggering on initial Form Load * FIO-8402: added test --- src/Webform.unit.js | 40 +++++++++++++++++++ .../_classes/component/Component.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Webform.unit.js b/src/Webform.unit.js index d663216822..741bf0b595 100644 --- a/src/Webform.unit.js +++ b/src/Webform.unit.js @@ -2297,6 +2297,46 @@ describe('Webform tests', function() { }); }); + it('Should not fire validation on calculated values init.', (done) => { + formElement.innerHTML = ''; + const form = new Webform(formElement,{ language: 'en' }); + form.setForm( + { title: 'noValidation flag', + components: [{ + label: 'minMax', + calculateValue: 'value = {minAmount: \'5.00\', maxAmount: \'50000.00\'};', + calculateServer: true, + key: 'minMax', + type: 'hidden', + input: true + }, { + label: 'A', + key: 'a', + type: 'number', + input: true + }, { + label: 'B', + key: 'b', + type: 'number', + input: true + }, { + label: 'Sum', + validate: { + required: true, + min: 10 + }, + calculateValue: 'var total = _.isNumber(data.a) ? data.a : 0;\ntotal += _.isNumber(data.b) ? data.b : 0;\n\nvalue = parseFloat(total.toFixed(2));', + calculateServer: true, + key: 'sum', + type: 'number', + input: true + }], + } + ).then(() => { + checkForErrors(form, {}, { data: {} }, 0, done); + }); + }); + it('Should set calculated value correctly', (done) => { formElement.innerHTML = ''; const form = new Webform(formElement); diff --git a/src/components/_classes/component/Component.js b/src/components/_classes/component/Component.js index 9a09190ada..3a0ac7fa1d 100644 --- a/src/components/_classes/component/Component.js +++ b/src/components/_classes/component/Component.js @@ -2972,7 +2972,7 @@ export default class Component extends Element { this.calculatedValue = fastCloneDeep(calculatedValue); if (changed) { - if (!flags.noPristineChangeOnModified) { + if (!flags.noPristineChangeOnModified && this.root.initialized) { this.pristine = false; } From d9c874f6aa71bc75a80616fa253975d131861619 Mon Sep 17 00:00:00 2001 From: lane-formio Date: Wed, 12 Jun 2024 10:26:12 -0500 Subject: [PATCH 4/7] Update Changelog.md --- Changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changelog.md b/Changelog.md index 85752286c8..91e34db18d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -256,6 +256,11 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e - FIO-8433: fixed restore draft for nested forms - FIO-8395: html in error message not evaluating - FIO-7206: Fixes an issue where API keys of the removed components are not removed from the Data Grid defaultValue + - FIO-8402: fixed an issue where Validation Triggering on initial Form load + - Remove *zoom (IE7 hack) + - made Formio available globally + - FIO-8027 added new Captcha provider + - FIO-8281: fixed selectData property for multiple select component ## 5.0.0-rc.37 ### Fixed From 4cf82e871949793d47f409accaa41a279714174f Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Fri, 14 Jun 2024 15:58:24 +0300 Subject: [PATCH 5/7] FIO-8493: added null check for this.root in builder mode --- src/components/form/Form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/form/Form.js b/src/components/form/Form.js index 62d270f2cb..5933249e4b 100644 --- a/src/components/form/Form.js +++ b/src/components/form/Form.js @@ -502,7 +502,7 @@ export default class FormComponent extends Component { } else if (this.formSrc) { this.subFormLoading = true; - const options = this.root.formio?.base && this.root.formio?.projectUrl + const options = this.root?.formio?.base && this.root?.formio?.projectUrl ? { base: this.root.formio.base, project: this.root.formio.projectUrl, @@ -711,7 +711,7 @@ export default class FormComponent extends Component { if (shouldLoadSubmissionById || shouldLoadDraftById) { const formId = submission.form || this.formObj.form || this.component.form; const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id || this.subForm.submission._id}`; - const options = this.root.formio?.base && this.root.formio?.projectUrl + const options = this.root?.formio?.base && this.root?.formio?.projectUrl ? { base: this.root.formio.base, project: this.root.formio.projectUrl, From 4463cff579669982c1138da830498374a52e9166 Mon Sep 17 00:00:00 2001 From: Jacob Nichols <32579287+ZenMasterJacob20011@users.noreply.github.com> Date: Tue, 18 Jun 2024 04:37:19 -0500 Subject: [PATCH 6/7] FIO-8420: file component no defaults causes error (#5642) * fixed file component upload error when no defaults is set to true * replace array.some with lodash.some --- src/components/file/File.js | 3 +-- src/components/file/File.unit.js | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/file/File.js b/src/components/file/File.js index 9ca3aebe98..08266c1c8c 100644 --- a/src/components/file/File.js +++ b/src/components/file/File.js @@ -744,8 +744,7 @@ export default class FileComponent extends Field { const fileWithSameNameUploading = this.filesToSync.filesToUpload .some(fileToSync => fileToSync.file?.name === file.name); - const fileWithSameNameUploaded = this.dataValue - .some(fileStatus => fileStatus.originalName === file.name); + const fileWithSameNameUploaded = _.some(this.dataValue, fileStatus => fileStatus.originalName === file.name); return fileWithSameNameUploaded || fileWithSameNameUploading ? { diff --git a/src/components/file/File.unit.js b/src/components/file/File.unit.js index 0a06811fc4..8c71d69e60 100644 --- a/src/components/file/File.unit.js +++ b/src/components/file/File.unit.js @@ -271,4 +271,10 @@ describe('File Component', () => { }, 100); }); }); + it('should not error on upload when noDefaults is set to true', () => { + return Formio.createForm(document.createElement('div'), comp2,{ noDefaults: true }).then((form)=>{ + const file = form.getComponent('file'); + return file.handleFilesToUpload([{ name: 'mypdf.pdf', size: 123123, type: 'application/pdf' }]); + }); + }); }); From d6c68eb03518dee76a7cfd844106971b3b9d8ad9 Mon Sep 17 00:00:00 2001 From: TanyaGashtold <61136841+TanyaGashtold@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:38:15 +0300 Subject: [PATCH 7/7] Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 91e34db18d..307d0f9ecd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -261,6 +261,7 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e - made Formio available globally - FIO-8027 added new Captcha provider - FIO-8281: fixed selectData property for multiple select component + - FIO-8420: file component no defaults causes error ## 5.0.0-rc.37 ### Fixed