From d44c1b93b32f4c83494767d233faf24a2326e944 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Thu, 23 May 2024 10:37:49 -0500 Subject: [PATCH 1/5] Updated jsdocs for addMessages --- src/components/_classes/component/Component.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/_classes/component/Component.js b/src/components/_classes/component/Component.js index 9daa721c25..36c12466fe 100644 --- a/src/components/_classes/component/Component.js +++ b/src/components/_classes/component/Component.js @@ -2133,8 +2133,7 @@ export default class Component extends Element { /** * Add a new input error to this element. * - * @param message - * @param dirty + * @param {{level: string, message: string}[]} messages */ addMessages(messages) { if (!messages) { From 897529c4b95762cb8599aa2f4a190533ca964e37 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Thu, 23 May 2024 10:39:07 -0500 Subject: [PATCH 2/5] Added apiKey error to translations --- src/translations/en.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/translations/en.js b/src/translations/en.js index 986556546a..efcb553c38 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -71,4 +71,5 @@ export default { submitButtonAriaLabel:'Submit Form button. Click to submit the form', reCaptchaTokenValidationError: 'ReCAPTCHA: Token validation error', reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission', + apiKey: 'API Key is not unique: {{key}}' }; From 77144cc49080fc5c2fb47e293a8b15f38e7bbaff Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Thu, 23 May 2024 10:44:28 -0500 Subject: [PATCH 3/5] setCustomValidity translates api key errors, removed unncessary error check --- src/WebformBuilder.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/WebformBuilder.js b/src/WebformBuilder.js index ea86442243..256386f271 100644 --- a/src/WebformBuilder.js +++ b/src/WebformBuilder.js @@ -1285,14 +1285,10 @@ export default class WebformBuilder extends Component { this.webform.everyComponent((comp) => { const path = comp.path; - const errors = comp.visibleErrors || []; if (repeatablePaths.includes(path)) { - comp.setCustomValidity(`API Key is not unique: ${comp.key}`); + comp.setCustomValidity(this.t('apiKey', { key: comp.key })); hasInvalidComponents = true; } - else if (errors.length && errors[0].message?.startsWith('API Key is not unique')) { - comp.setCustomValidity(''); - } }); this.emit('builderFormValidityChange', hasInvalidComponents); From ae40c770db9a982c07755e99608ab5feee250ec5 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Fri, 24 May 2024 11:52:42 -0500 Subject: [PATCH 4/5] tests for api key error and translation --- src/Webform.unit.js | 2 +- src/WebformBuilder.unit.js | 23 ++++++++- test/formtest/index.d.ts | 2 +- test/formtest/index.js | 2 + test/formtest/uniqueApiKeysTranslation.json | 53 +++++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 test/formtest/uniqueApiKeysTranslation.json diff --git a/src/Webform.unit.js b/src/Webform.unit.js index 53c9ae846b..02445e6109 100644 --- a/src/Webform.unit.js +++ b/src/Webform.unit.js @@ -1270,7 +1270,7 @@ describe('Webform tests', function() { .catch((err) => done(err)); }); - it('Should show validation errors and update validation errors list when opening and editing edit grid rows in draft modal mode after pushing submit btn', function(done) { + it.skip('Should show validation errors and update validation errors list when opening and editing edit grid rows in draft modal mode after pushing submit btn',function(done) { const formElement = document.createElement('div'); const formWithDraftModals = new Webform(formElement, { sanitize: true }); diff --git a/src/WebformBuilder.unit.js b/src/WebformBuilder.unit.js index 27d34ea946..ba01b0b515 100644 --- a/src/WebformBuilder.unit.js +++ b/src/WebformBuilder.unit.js @@ -3,7 +3,7 @@ import Harness from '../test/harness'; import WebformBuilder from './WebformBuilder'; import Builders from './builders'; import { Formio } from './Formio'; -import { uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, columnsForm, resourceKeyCamelCase } from '../test/formtest'; +import { uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, columnsForm, resourceKeyCamelCase, uniqueApiKeysTranslation } from '../test/formtest'; import sameApiKeysLayoutComps from '../test/forms/sameApiKeysLayoutComps'; import testApiKeysUniquifying from '../test/forms/testApiKeysUniquifying'; import formBasedOnWizard from '../test/forms/formBasedOnWizard'; @@ -32,6 +32,27 @@ describe('WebformBuilder tests', function() { done(); }, 500); }); + it('Should show API Key is not unique: {{key}} error when api keys are the same', (done) => { + const builder = Harness.getBuilder(); + builder.i18next.currentLanguage = { apiKey: 'translated api key error {{key}}' }; + builder.webform.setForm(uniqueApiKeysTranslation).then(()=>{ + builder.highlightInvalidComponents(); + const component = builder.webform.getComponent(['textField']); + assert.equal(component.visibleErrors.length, 1); + done(); + }).catch(done); + }); + + it('Should show translated api key error {{key}} when apiKey is overridden in i18next translations', (done) => { + const builder = Harness.getBuilder(); + builder.i18next.currentLanguage = { apiKey: 'translated api key error {{key}}' }; + builder.webform.setForm(uniqueApiKeysTranslation).then(() => { + builder.highlightInvalidComponents(); + const component = builder.webform.getComponent(['textField']); + assert.equal(component.visibleErrors[0].message,'translated api key error textField'); + done(); + }).catch(done); + }); it('Should not show unique API error when components with same keys are inside and outside of the Data component', (done) => { const builder = Harness.getBuilder(); diff --git a/test/formtest/index.d.ts b/test/formtest/index.d.ts index dfd6d0a3d1..ec628ae9ca 100644 --- a/test/formtest/index.d.ts +++ b/test/formtest/index.d.ts @@ -1 +1 @@ -export { advanced, basic, data, defaults, layout, premium, settingErrors, clearOnHide, manualOverride, uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, validationOnBlur, calculateValueWithManualOverride, calculateValueWithSubmissionMetadata, displayAsModalEditGrid, formWithAdvancedLogic, formWithPatternValidation, calculatedSelectboxes, columnsForm, calculateZeroValue, formWithConditionalLogic, formWithCalculatedValueWithoutOverriding, formWithTimeComponent, formWithEditGridModalDrafts, formWithBlurValidationInsidePanel, modalEditComponents, calculatedNotPersistentValue, calculateValueInEditingMode, initiallyCollapsedPanel, multipleTextareaInsideConditionalComponent, formComponentWithConditionalRenderingForm, disabledNestedForm, propertyActions, formWithEditGridAndNestedDraftModalRow, formWithDateTimeComponents, formWithCollapsedPanel, formWithCustomFormatDate, wizardWithHiddenPanel, wizardWithSimpleConditionalPage, wizardWithTooltip, resourceKeyCamelCase, tooltipActivateCheckbox }; +export { advanced, basic, data, defaults, layout, premium, settingErrors, clearOnHide, manualOverride, uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, validationOnBlur, calculateValueWithManualOverride, calculateValueWithSubmissionMetadata, displayAsModalEditGrid, formWithAdvancedLogic, formWithPatternValidation, calculatedSelectboxes, columnsForm, calculateZeroValue, formWithConditionalLogic, formWithCalculatedValueWithoutOverriding, formWithTimeComponent, formWithEditGridModalDrafts, formWithBlurValidationInsidePanel, modalEditComponents, calculatedNotPersistentValue, calculateValueInEditingMode, initiallyCollapsedPanel, multipleTextareaInsideConditionalComponent, formComponentWithConditionalRenderingForm, disabledNestedForm, propertyActions, formWithEditGridAndNestedDraftModalRow, formWithDateTimeComponents, formWithCollapsedPanel, formWithCustomFormatDate, wizardWithHiddenPanel, wizardWithSimpleConditionalPage, wizardWithTooltip, resourceKeyCamelCase, tooltipActivateCheckbox, uniqueApiKeysTranslation }; diff --git a/test/formtest/index.js b/test/formtest/index.js index 4b21cb8e25..ac4d15f9fa 100644 --- a/test/formtest/index.js +++ b/test/formtest/index.js @@ -10,6 +10,7 @@ const manualOverride = require('./manualOverride.json'); const uniqueApiKeys = require('./uniqueApiKeys.json'); const uniqueApiKeysLayout = require('./uniqueApiKeysLayout.json'); const uniqueApiKeysSameLevel = require('./uniqueApiKeysSameLevel.json'); +const uniqueApiKeysTranslation = require('./uniqueApiKeysTranslation.json'); const validationOnBlur = require('./validationOnBlur.json'); const calculateValueWithManualOverride = require('./calculateValueWithManualOverride.json'); const calculateValueWithSubmissionMetadata = require('./calculateValueWithSubmissionMetadata.json'); @@ -56,6 +57,7 @@ module.exports = { uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, + uniqueApiKeysTranslation, validationOnBlur, calculateValueWithManualOverride, calculateValueWithSubmissionMetadata, diff --git a/test/formtest/uniqueApiKeysTranslation.json b/test/formtest/uniqueApiKeysTranslation.json new file mode 100644 index 0000000000..47aad0aaad --- /dev/null +++ b/test/formtest/uniqueApiKeysTranslation.json @@ -0,0 +1,53 @@ +{ + "_id": "6650ac72fab50fab9668c1e8", + "title": "uniqueAPIKeysTranslation", + "name": "uniqueApiKeysTranslation", + "path": "uniqueapikeystranslation", + "type": "form", + "display": "form", + "tags": [], + "access": [ + { + "type": "read_all", + "roles": [ + "664ccde9fab50fab9641b6d8", + "664ccde9fab50fab9641b6e0", + "664ccde9fab50fab9641b6e4" + ] + } + ], + "submissionAccess": [], + "owner": "659f068baa3ac0e81cf5f6c0", + "components": [ + { + "label": "Text Field", + "applyMaskOn": "change", + "tableView": true, + "key": "textField", + "type": "textfield", + "input": true + }, + { + "label": "Text Area", + "applyMaskOn": "change", + "autoExpand": false, + "tableView": true, + "key": "textField", + "type": "textarea", + "input": true + } + ], + "settings": { + + }, + "properties": { + + }, + "project": "664ccde8fab50fab9641b6d1", + "controller": "", + "revisions": "", + "submissionRevisions": "", + "_vid": 0, + "created": "2024-05-24T15:04:18.259Z", + "modified": "2024-05-24T15:04:18.261Z" +} From 3476921b42bc9827378cb0f75b43065f7ede6d34 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Fri, 24 May 2024 12:46:54 -0500 Subject: [PATCH 5/5] Ran test:updateRenders to add uniqueApiKeysTranslation.html files to renders --- src/Webform.unit.js | 2 +- ...rap-readOnly-uniqueApiKeysTranslation.html | 27 +++++++++++++++++++ ...rm-bootstrap-uniqueApiKeysTranslation.html | 23 ++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/renders/form-bootstrap-readOnly-uniqueApiKeysTranslation.html create mode 100644 test/renders/form-bootstrap-uniqueApiKeysTranslation.html diff --git a/src/Webform.unit.js b/src/Webform.unit.js index 02445e6109..0d32c16003 100644 --- a/src/Webform.unit.js +++ b/src/Webform.unit.js @@ -1270,7 +1270,7 @@ describe('Webform tests', function() { .catch((err) => done(err)); }); - it.skip('Should show validation errors and update validation errors list when opening and editing edit grid rows in draft modal mode after pushing submit btn',function(done) { + it('Should show validation errors and update validation errors list when opening and editing edit grid rows in draft modal mode after pushing submit btn',function(done) { const formElement = document.createElement('div'); const formWithDraftModals = new Webform(formElement, { sanitize: true }); diff --git a/test/renders/form-bootstrap-readOnly-uniqueApiKeysTranslation.html b/test/renders/form-bootstrap-readOnly-uniqueApiKeysTranslation.html new file mode 100644 index 0000000000..d4c14b9795 --- /dev/null +++ b/test/renders/form-bootstrap-readOnly-uniqueApiKeysTranslation.html @@ -0,0 +1,27 @@ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/test/renders/form-bootstrap-uniqueApiKeysTranslation.html b/test/renders/form-bootstrap-uniqueApiKeysTranslation.html new file mode 100644 index 0000000000..a1dccafb00 --- /dev/null +++ b/test/renders/form-bootstrap-uniqueApiKeysTranslation.html @@ -0,0 +1,23 @@ +
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+
+
\ No newline at end of file