@bcrs-shared-components/base-address 2.2.1 → 2.2.2

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.
Files changed (2) hide show
  1. package/BaseAddress.vue +10 -3
  2. package/package.json +2 -2
package/BaseAddress.vue CHANGED
@@ -165,7 +165,7 @@ import { Validations } from 'vuelidate-property-decorators'
165
165
  import { uniqueId } from 'lodash'
166
166
  import { ValidationMixin, CountriesProvincesMixin } from '@bcrs-shared-components/mixins'
167
167
  import { FormIF } from '@bcrs-shared-components/interfaces'
168
-
168
+ import { isPostalCodeOptionalForCountry } from '@/validators'
169
169
  /**
170
170
  * The component for displaying and editing an address.
171
171
  * Vuelidate is used to implement the validation rules (eg, what 'required' means and whether it's satisfied).
@@ -335,7 +335,14 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
335
335
  } else {
336
336
  label = 'Postal Code'
337
337
  }
338
- return label + (this.isSchemaRequired('postalCode') ? '' : ' (Optional)')
338
+
339
+ let isRequired = this.isSchemaRequired('postalCode')
340
+ // If schema uses isRequiredPostalCode validator, check if country requires postal codes
341
+ if (!isRequired && this.schemaLocal?.postalCode?.isRequiredPostalCode) {
342
+ isRequired = !isPostalCodeOptionalForCountry(this.addressCountry)
343
+ }
344
+
345
+ return label + (isRequired ? '' : ' (Optional)')
339
346
  }
340
347
 
341
348
  /** The Address Country label with 'optional' as needed. */
@@ -358,7 +365,7 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
358
365
 
359
366
  /** Whether the specified prop is required according to the schema. */
360
367
  isSchemaRequired (prop: string): boolean {
361
- return Boolean(this.schemaLocal && this.schemaLocal[prop] && this.schemaLocal[prop].required)
368
+ return Boolean(this.schemaLocal?.[prop]?.required)
362
369
  }
363
370
 
364
371
  /** Array of validation rules used by input elements to prevent extra whitespace. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bcrs-shared-components/base-address",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,5 +14,5 @@
14
14
  "vue-property-decorator": "^9.1.2",
15
15
  "vuelidate-property-decorators": "1.0.28"
16
16
  },
17
- "gitHead": "30eec9b5b0bc7d7d35c3373e0acd6007ba6a1476"
17
+ "gitHead": "4c249d93bf6b86ad7d1c9bfd205fee2cca3edb45"
18
18
  }