Skip to content

Commit

Permalink
FIO-8912: fix normalization in submission (#5798)
Browse files Browse the repository at this point in the history
* fix  normalization in submission

* update deps; account for an emptyValue type of array

* update deps
  • Loading branch information
brendanbond authored Sep 9, 2024
1 parent 075c8b8 commit 4c999da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"dependencies": {
"@formio/bootstrap": "3.0.0-dev.98.17ba6ea",
"@formio/choices.js": "^10.2.1",
"@formio/core": "2.1.0-dev.105.1bff2e6",
"@formio/core": "2.1.0-dev.145.4491833",
"@formio/text-mask-addons": "^3.8.0-formio.2",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand Down
4 changes: 2 additions & 2 deletions src/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ describe('WebformBuilder tests', function() {
const dayComp = builder.webform.getComponent(['day']);
assert.equal(dayComp.component.maxDate, 'moment().add(10, \'days\')');
done();
}, 200);
}, 200);
}, 500);
}, 500);
}, 500);
}).catch(done);
});
Expand Down
23 changes: 12 additions & 11 deletions src/components/_classes/multivalue/Multivalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,39 @@ export default class Multivalue extends Field {
/**
* Normalize values coming into updateValue.
* @param {*} value - The value to normalize before setting.
* @param {Object} flags - Flags to use when normalizing the value.
* @param {*} emptyValue - The empty value for the field.
* @returns {*} - The normalized value.
*/
normalizeValue(value) {
normalizeValue(value, flags = {}, emptyValue = this.emptyValue) {
if (this.component.multiple) {
if (Array.isArray(value)) {
if (value.length === 0) {
return [this.emptyValue];
return [emptyValue];
}

if (this.component.storeas === 'array') {
return super.normalizeValue([value]);
return super.normalizeValue([value], flags);
}

return super.normalizeValue(value);
return super.normalizeValue(value, flags);
} else {
return super.normalizeValue(value == null ? [this.emptyValue] : [value]);
return super.normalizeValue(value == null ? [emptyValue] : [value], flags);
}
} else {
if (Array.isArray(value) && this.component.storeas !== 'array') {
if (Array.isArray(value) && !Array.isArray(emptyValue)) {
if (this.component.storeas === 'string') {
return super.normalizeValue(value.join(this.delimiter || ''));
return super.normalizeValue(value.join(this.delimiter || ''), flags);
}
return super.normalizeValue(value[0] || this.emptyValue);
return super.normalizeValue(value[0] || emptyValue, flags);
} else {
return super.normalizeValue(value);
return super.normalizeValue(value, flags);
}
}
}

get dataValue() {
return super.dataValue;
return this.normalizeValue(super.dataValue);
}

set dataValue(value) {
Expand All @@ -44,7 +46,6 @@ export default class Multivalue extends Field {

get defaultValue() {
let value = super.defaultValue;

if (this.component.multiple) {
if (_.isArray(value)) {
value = !value.length ? [super.emptyValue] : value;
Expand Down
50 changes: 20 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,21 @@
fuse.js "^6.6.2"
redux "^4.2.0"

"@formio/[email protected].105.1bff2e6":
version "2.1.0-dev.105.1bff2e6"
resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.105.1bff2e6.tgz#068bf67444641692f3f8037b16ec4c69c033c91e"
integrity sha512-bIbWLn2/Lg6nYKqUYlNDcuF7EH7pIUNUzQBR1XDQ7P0LucK8ukG5Y8A3WOmVtR8S++VShSw8pzapnCytutDA7g==
"@formio/[email protected].145.4491833":
version "2.1.0-dev.145.4491833"
resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.145.4491833.tgz#f8bb24949e71d865a2ec354a3f58dc5bf56dcde6"
integrity sha512-mN9tymogT+6qWbwlVTNB3xGI+sk9sz4WYxe7BW66fuPpsUsYwxuUtSrnGbM8WInkqmj7aNZrXd5WQ2SAV93wjQ==
dependencies:
"@types/json-logic-js" "^2.0.7"
browser-cookies "^1.2.0"
core-js "^3.37.1"
dayjs "^1.11.11"
dompurify "^3.1.4"
core-js "^3.38.0"
dayjs "^1.11.12"
dompurify "^3.1.6"
eventemitter3 "^5.0.0"
fast-json-patch "^3.1.1"
fetch-ponyfill "^7.1.0"
inputmask "5.0.8"
json-logic-js "^2.0.2"
inputmask "5.0.9"
json-logic-js "^2.0.5"
lodash "^4.17.21"
moment "^2.29.4"

Expand Down Expand Up @@ -1904,6 +1904,11 @@ core-js@^3.0.0, core-js@^3.30.2, core-js@^3.37.1:
resolved "https://registry.npmjs.org/core-js/-/core-js-3.37.1.tgz#d21751ddb756518ac5a00e4d66499df981a62db9"
integrity sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==

core-js@^3.38.0:
version "3.38.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.38.1.tgz#aa375b79a286a670388a1a363363d53677c0383e"
integrity sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==

[email protected]:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -2048,10 +2053,10 @@ date-format@^4.0.14:
resolved "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz#7a8e584434fb169a521c8b7aa481f355810d9400"
integrity sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==

dayjs@^1.11.11:
version "1.11.11"
resolved "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz#dfe0e9d54c5f8b68ccf8ca5f72ac603e7e5ed59e"
integrity sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==
dayjs@^1.11.12:
version "1.11.13"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.13.tgz#92430b0139055c3ebb60150aa13e860a4b5a366c"
integrity sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==

debounce@^1.2.1:
version "1.2.1"
Expand Down Expand Up @@ -2294,11 +2299,6 @@ domexception@^4.0.0:
dependencies:
webidl-conversions "^7.0.0"

dompurify@^3.1.4:
version "3.1.5"
resolved "https://registry.npmjs.org/dompurify/-/dompurify-3.1.5.tgz#2c6a113fc728682a0f55684b1388c58ddb79dc38"
integrity sha512-lwG+n5h8QNpxtyrJW/gJWckL+1/DQiYMX8f7t8Z2AZTPw1esVrqjI63i7Zc2Gz0aKzLVMYC1V1PL/ky+aY/NgA==

dompurify@^3.1.6:
version "3.1.6"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.1.6.tgz#43c714a94c6a7b8801850f82e756685300a027e2"
Expand Down Expand Up @@ -3974,14 +3974,9 @@ ini@^1.3.4:
resolved "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

[email protected]:
version "5.0.8"
resolved "https://registry.npmjs.org/inputmask/-/inputmask-5.0.8.tgz#cd0f70b058c3291a0d4f27de25dbfc179c998bb4"
integrity sha512-1WcbyudPTXP1B28ozWWyFa6QRIUG4KiLoyR6LFHlpT4OfTzRqFfWgHFadNvRuMN1S9XNVz9CdNvCGjJi+uAMqQ==

inputmask@^5.0.8:
[email protected], inputmask@^5.0.8:
version "5.0.9"
resolved "https://registry.npmjs.org/inputmask/-/inputmask-5.0.9.tgz#7bf4e83f5e199c88c0edf28545dc23fa208ef4be"
resolved "https://registry.yarnpkg.com/inputmask/-/inputmask-5.0.9.tgz#7bf4e83f5e199c88c0edf28545dc23fa208ef4be"
integrity sha512-s0lUfqcEbel+EQXtehXqwCJGShutgieOaIImFKC/r4reYNvX3foyrChl6LOEvaEgxEbesePIrw1Zi2jhZaDZbQ==

internal-slot@^1.0.7:
Expand Down Expand Up @@ -4553,11 +4548,6 @@ [email protected]:
resolved "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13"
integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==

json-logic-js@^2.0.2:
version "2.0.2"
resolved "https://registry.npmjs.org/json-logic-js/-/json-logic-js-2.0.2.tgz#b613e095f5e598cb78f7b9a2bbf638e74cf98158"
integrity sha512-ZBtBdMJieqQcH7IX/LaBsr5pX+Y5JIW+EhejtM3Ffg2jdN9Iwf+Ht6TbHnvAZ/YtwyuhPaCBlnvzrwVeWdvGDQ==

json-logic-js@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/json-logic-js/-/json-logic-js-2.0.5.tgz#55f0c687dd6f56b02ccdcfdd64171ed998ab5499"
Expand Down

0 comments on commit 4c999da

Please sign in to comment.