@sbc-connect/nuxt-forms 0.6.2 → 0.7.0

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,11 @@
1
1
  # @sbc-connect/nuxt-forms
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
3
9
  ## 0.6.2
4
10
 
5
11
  ### 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
  ? '*** ***'
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "name": "@sbc-connect/nuxt-forms",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "repository": "github:bcgov/connect-nuxt",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./nuxt.config.ts",
@@ -11,8 +11,8 @@
11
11
  "nuxt": "4.2.2",
12
12
  "typescript": "5.9.3",
13
13
  "vue-tsc": "3.2.1",
14
- "@sbc-connect/playwright-config": "0.1.1",
15
14
  "@sbc-connect/eslint-config": "0.0.8",
15
+ "@sbc-connect/playwright-config": "0.1.1",
16
16
  "@sbc-connect/vitest-config": "0.1.0"
17
17
  },
18
18
  "dependencies": {