From 1bca8ff89072f88f23b433395ff67087975d07fa Mon Sep 17 00:00:00 2001 From: TanyaGashtold <61136841+TanyaGashtold@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:39:06 +0300 Subject: [PATCH] FIO-9511: fixed day min/max validation message (#5965) --- package.json | 2 +- src/components/day/Day.js | 20 ++------------------ src/translations/en.js | 4 ++-- test/unit/Day.unit.js | 4 ++++ yarn.lock | 39 +++++++-------------------------------- 5 files changed, 16 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index fdb2dd6994..8405a5c063 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "dependencies": { "@formio/bootstrap": "3.1.0-dev.1-dev.120.01bbe80", "@formio/choices.js": "^10.2.1", - "@formio/core": "2.4.0-dev.205.f4cc49f", + "@formio/core": "v2.4.0-dev.210.e634ab4", "@formio/text-mask-addons": "3.8.0-formio.4", "@formio/vanilla-text-mask": "^5.1.1-formio.1", "abortcontroller-polyfill": "^1.7.5", diff --git a/src/components/day/Day.js b/src/components/day/Day.js index 4b73d5c087..b64041b6d8 100644 --- a/src/components/day/Day.js +++ b/src/components/day/Day.js @@ -2,6 +2,7 @@ import _ from 'lodash'; import moment from 'moment'; import Field from '../_classes/field/Field'; import { boolValue, componentValueTypes, getComponentSavedTypes, getLocaleDateFormatInfo } from '../../utils/utils'; +import { getDayFormat } from '@formio/core'; export default class DayComponent extends Field { static schema(...extend) { @@ -536,24 +537,7 @@ export default class DayComponent extends Field { * @returns {string} - the format for the value string. */ get format() { - let format = ''; - if (this.component.dayFirst && this.showDay) { - format += 'D/'; - } - if (this.showMonth) { - format += 'M/'; - } - if (!this.component.dayFirst && this.showDay) { - format += 'D/'; - } - if (this.showYear) { - format += 'YYYY'; - return format; - } - else { - // Trim off the "/" from the end of the format string. - return format.length ? format.substring(0, format.length - 1) : format; - } + return getDayFormat(this.component); } /** diff --git a/src/translations/en.js b/src/translations/en.js index 91cd37bb30..ddffb90110 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -28,8 +28,8 @@ export default { maxWords: '{{field}} must have no more than {{length}} words.', min: '{{field}} cannot be less than {{min}}.', max: '{{field}} cannot be greater than {{max}}.', - maxDate: '{{field}} should not contain date after {{- maxDate}}', - minDate: '{{field}} should not contain date before {{- minDate}}', + maxDate: '{{field}} should not contain date after {{maxDate}}', + minDate: '{{field}} should not contain date before {{minDate}}', maxYear: '{{field}} should not contain year greater than {{maxYear}}', minYear: '{{field}} should not contain year less than {{minYear}}', minSelectedCount: 'You must select at least {{minCount}} items', diff --git a/test/unit/Day.unit.js b/test/unit/Day.unit.js index 6af3e5a026..cf09fefaca 100644 --- a/test/unit/Day.unit.js +++ b/test/unit/Day.unit.js @@ -190,9 +190,13 @@ describe('Day Component', () => { Harness.testCreate(DayComponent, comp3).then((component) => { component.setValue('01/02/2020'); assert(!component.checkValidity(component.data, true), 'Component should not be valid'); + assert.equal(component.errors?.length, 1); + assert.equal(component.errors[0]?.message, 'Date should not contain date before 1/3/2020'); component.setValue('04/01/2021'); assert(!component.checkValidity(component.data, true), 'Component should not be valid'); + assert.equal(component.errors?.length, 1); + assert.equal(component.errors[0]?.message, 'Date should not contain date after 3/1/2021'); component.setValue('03/01/2021'); assert(component.checkValidity(component.data, true), 'Component should be valid'); diff --git a/yarn.lock b/yarn.lock index 0cc71d3a72..234bfd503b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -223,10 +223,10 @@ fuse.js "^6.6.2" redux "^4.2.0" -"@formio/core@2.4.0-dev.205.f4cc49f": - version "2.4.0-dev.205.f4cc49f" - resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.4.0-dev.205.f4cc49f.tgz#9cf71bfe12575666ecfe40592c8ebd622784d721" - integrity sha512-uA2a5TUlr/I+pIYBTZY5SiJyg/UrmpMpzS0fgWis4+4OZHD4L81epGBVndN1M7TxpNpcqBzdpJVe/mzuilGgNA== +"@formio/core@v2.4.0-dev.210.e634ab4": + version "2.4.0-dev.210.e634ab4" + resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.4.0-dev.210.e634ab4.tgz#1f8d0e216b2a103ca9945a4cdc86683be48e4bbd" + integrity sha512-t+M9K3si9Sd11dTN7Yzrek5l7V71AifjxM9RvbpJKOPr3P4f0Ceq1Z9P4vESQ8rCBAV3SAVwXzoeSGcVx7b6/Q== dependencies: browser-cookies "^1.2.0" core-js "^3.39.0" @@ -7442,7 +7442,7 @@ string-replace-loader@^3.1.0: loader-utils "^2.0.0" schema-utils "^3.0.0" -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -7460,15 +7460,6 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" -string-width@^4.1.0, string-width@^4.2.0: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -7533,7 +7524,7 @@ stringifier@^1.3.0: traverse "^0.6.6" type-name "^2.0.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -7554,13 +7545,6 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -8657,7 +8641,7 @@ workerpool@^6.5.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544" integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -8683,15 +8667,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"