@sbc-connect/nuxt-forms 0.6.2 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @sbc-connect/nuxt-forms
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149](https://github.com/bcgov/connect-nuxt/pull/149) [`467e679`](https://github.com/bcgov/connect-nuxt/commit/467e679f8bf4b2f3b9ec2294fd28a2a6c5ef3dba) Thanks [@deetz99](https://github.com/deetz99)! - Update dependencies
8
+
9
+ - Updated dependencies [[`467e679`](https://github.com/bcgov/connect-nuxt/commit/467e679f8bf4b2f3b9ec2294fd28a2a6c5ef3dba)]:
10
+ - @sbc-connect/nuxt-base@0.7.2
11
+
12
+ ## 0.7.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#144](https://github.com/bcgov/connect-nuxt/pull/144) [`3b9fddb`](https://github.com/bcgov/connect-nuxt/commit/3b9fddb1c634fa48c8f4426954cbb2a043f78ff1) Thanks [@eve-git](https://github.com/eve-git)! - Fix issue where postal code was not optional for certain countries.
17
+
3
18
  ## 0.6.2
4
19
 
5
20
  ### Patch Changes
@@ -7,6 +7,14 @@ defineProps<{
7
7
  required?: boolean
8
8
  }>()
9
9
 
10
+ const isOptionalPostalCodeCountry = (country?: string) => {
11
+ if (!country) {
12
+ return false
13
+ }
14
+
15
+ return isNoPostalCodeCountry(country)
16
+ }
17
+
10
18
  const model = defineModel<string | undefined>({
11
19
  set(value) {
12
20
  if (value) {
@@ -24,10 +32,12 @@ const model = defineModel<string | undefined>({
24
32
  :data-testid="`${parentId}-field-postalCode`"
25
33
  :input-id="`${parentId}-input-postalCode`"
26
34
  :disabled
27
- :required
35
+ :required="required && !isOptionalPostalCodeCountry(country)"
28
36
  :label="country === 'US'
29
37
  ? $t('connect.label.zipCode')
30
- : $t('connect.label.postalCode')
38
+ : isOptionalPostalCodeCountry(country)
39
+ ? $t('connect.label.postalCodeOpt')
40
+ : $t('connect.label.postalCode')
31
41
  "
32
42
  :mask="country === 'CA'
33
43
  ? '*** ***'
@@ -1,4 +1,6 @@
1
1
  <script setup lang="ts">
2
+ import type { TextareaProps } from '@nuxt/ui'
3
+
2
4
  defineProps<{
3
5
  name: string
4
6
  label: string
@@ -9,7 +11,7 @@ defineProps<{
9
11
  help?: string
10
12
  }>()
11
13
 
12
- const model = defineModel<null | string | number | undefined>({ required: true })
14
+ const model = defineModel<Exclude<TextareaProps['modelValue'], null>>({ required: true })
13
15
  </script>
14
16
 
15
17
  <template>
@@ -2034,3 +2034,15 @@ export const isoCountriesListSortedByName = isoCountriesList.toSorted(
2034
2034
  return 0
2035
2035
  }
2036
2036
  )
2037
+
2038
+ const NO_POSTAL_CODE_COUNTRY_CODES = [
2039
+ 'AO', 'AG', 'AW', 'BS', 'BZ', 'BJ', 'BM', 'BO', 'BQ', 'BW', 'BF', 'BI',
2040
+ 'CM', 'CF', 'TD', 'KM', 'CG', 'CD', 'CK', 'CI', 'CW', 'DJ', 'DM', 'GQ',
2041
+ 'ER', 'FJ', 'TF', 'GA', 'GM', 'GH', 'GD', 'GY', 'HM', 'HK',
2042
+ 'KI', 'KP', 'LY', 'MO', 'MW', 'ML', 'MR', 'NR',
2043
+ 'AN', 'NU', 'QA', 'RW', 'KN', 'ST', 'SC', 'SL', 'SX', 'SB', 'SO', 'SR', 'SY',
2044
+ 'TL', 'TG', 'TK', 'TO', 'TT', 'TV', 'UG', 'AE', 'VU', 'YE', 'ZW'
2045
+ ]
2046
+ export function isNoPostalCodeCountry(countryCode: string): boolean {
2047
+ return NO_POSTAL_CODE_COUNTRY_CODES.indexOf(countryCode) !== -1
2048
+ }
@@ -55,6 +55,7 @@ export function getRequiredAddressSchema() {
55
55
  }
56
56
 
57
57
  const isRequiredRegion = country === 'US' || country === 'CA'
58
+ const isRequiredPostalCode = !!country && !isNoPostalCodeCountry(country)
58
59
 
59
60
  if (isRequiredRegion) {
60
61
  if (!region) {
@@ -64,14 +65,14 @@ export function getRequiredAddressSchema() {
64
65
  path: ['region']
65
66
  })
66
67
  }
68
+ }
67
69
 
68
- if (!postalCode) {
69
- ctx.addIssue({
70
- code: 'custom',
71
- message: t('connect.validation.fieldRequired'),
72
- path: ['postalCode']
73
- })
74
- }
70
+ if (isRequiredPostalCode && !postalCode) {
71
+ ctx.addIssue({
72
+ code: 'custom',
73
+ message: t('connect.validation.fieldRequired'),
74
+ path: ['postalCode']
75
+ })
75
76
  }
76
77
 
77
78
  if (!postalCode) {
@@ -17,6 +17,7 @@ export default {
17
17
  locationDescriptionOpt: 'Location Description (Optional)',
18
18
  mailingAddress: 'Mailing Address',
19
19
  postalCode: 'Postal Code',
20
+ postalCodeOpt: 'Postal Code (Optional)',
20
21
  province: 'Province',
21
22
  region: 'Region',
22
23
  regionOpt: 'Region (Optional)',
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@sbc-connect/nuxt-forms",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.1",
5
5
  "repository": "github:bcgov/connect-nuxt",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./nuxt.config.ts",
8
8
  "devDependencies": {
9
- "@axe-core/playwright": "4.11.0",
10
- "dotenv": "17.2.3",
9
+ "@axe-core/playwright": "4.11.1",
10
+ "dotenv": "17.3.1",
11
11
  "nuxt": "4.2.2",
12
12
  "typescript": "5.9.3",
13
- "vue-tsc": "3.2.1",
14
- "@sbc-connect/playwright-config": "0.1.1",
13
+ "vue-tsc": "3.2.5",
15
14
  "@sbc-connect/eslint-config": "0.0.8",
16
- "@sbc-connect/vitest-config": "0.1.0"
15
+ "@sbc-connect/playwright-config": "0.1.1",
16
+ "@sbc-connect/vitest-config": "0.1.1"
17
17
  },
18
18
  "dependencies": {
19
19
  "country-codes-list": "2.0.0",
20
20
  "vue-country-flag-next": "2.3.2",
21
- "@sbc-connect/nuxt-base": "0.7.1"
21
+ "@sbc-connect/nuxt-base": "0.7.2"
22
22
  },
23
23
  "scripts": {
24
24
  "preinstall": "npx only-allow pnpm",