@bcrs-shared-components/base-address 2.0.59 → 2.0.61
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/BaseAddress.vue +28 -18
- package/package.json +3 -3
package/BaseAddress.vue
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2020 Province of British Columbia
|
|
3
|
-
//
|
|
4
|
-
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
|
5
|
-
// the License. You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
10
|
-
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
11
|
-
// specific language governing permissions and limitations under the License.
|
|
12
|
-
//
|
|
13
|
-
|
|
14
1
|
<template>
|
|
15
2
|
<div class="base-address">
|
|
16
3
|
<!-- Display fields -->
|
|
@@ -148,8 +135,9 @@
|
|
|
148
135
|
filled
|
|
149
136
|
class="item postal-code"
|
|
150
137
|
:label="postalCodeLabel"
|
|
151
|
-
:rules="[...rules.postalCode, ...spaceRules]"
|
|
138
|
+
:rules="postalCodeRulesEnabled ? [...rules.postalCode, ...spaceRules] : []"
|
|
152
139
|
@input="addressLocal.postalCode = addressLocal.postalCode?.toUpperCase()"
|
|
140
|
+
@blur="postalCodeRulesEnabled = true"
|
|
153
141
|
/>
|
|
154
142
|
</div>
|
|
155
143
|
<div class="form__row">
|
|
@@ -175,6 +163,7 @@ import { Component, Mixins, Emit, Prop, Watch } from 'vue-property-decorator'
|
|
|
175
163
|
import { Validations } from 'vuelidate-property-decorators'
|
|
176
164
|
import { uniqueId } from 'lodash'
|
|
177
165
|
import { ValidationMixin, CountriesProvincesMixin } from '@bcrs-shared-components/mixins'
|
|
166
|
+
import { FormIF } from '@bcrs-shared-components/interfaces'
|
|
178
167
|
|
|
179
168
|
/**
|
|
180
169
|
* The component for displaying and editing an address.
|
|
@@ -188,7 +177,7 @@ import { ValidationMixin, CountriesProvincesMixin } from '@bcrs-shared-component
|
|
|
188
177
|
export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvincesMixin) {
|
|
189
178
|
// Refs
|
|
190
179
|
$refs!: {
|
|
191
|
-
addressForm:
|
|
180
|
+
addressForm: FormIF
|
|
192
181
|
}
|
|
193
182
|
|
|
194
183
|
/**
|
|
@@ -237,12 +226,29 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
237
226
|
@Prop({ default: false })
|
|
238
227
|
readonly isInactive: boolean
|
|
239
228
|
|
|
229
|
+
/** Called, possibly externally, to validate all registered form inputs. */
|
|
230
|
+
public validate (): any {
|
|
231
|
+
this.postalCodeRulesEnabled = true
|
|
232
|
+
return this.$refs.addressForm.validate()
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Called, possibly externally, to reset validation of all registered form inputs and clear their values. */
|
|
236
|
+
public reset (): any {
|
|
237
|
+
this.postalCodeRulesEnabled = false
|
|
238
|
+
return this.$refs.addressForm.reset()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Called, possibly externally, to reset validation of all registered form inputs without modifying their values. */
|
|
242
|
+
public resetValidation (): any {
|
|
243
|
+
return this.$refs.addressForm.resetValidation()
|
|
244
|
+
}
|
|
245
|
+
|
|
240
246
|
/** When country changes, resets fields. */
|
|
241
247
|
onCountryChange () {
|
|
242
248
|
this.addressLocal['addressRegion'] = ''
|
|
243
249
|
this.addressLocal['postalCode'] = ''
|
|
244
250
|
// clear any existing validation errors
|
|
245
|
-
this
|
|
251
|
+
this.resetValidation()
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
/** A local (working) copy of the address, to contain the fields edited by the component (ie, the model). */
|
|
@@ -254,6 +260,9 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
254
260
|
/** A unique id for this instance of this component. */
|
|
255
261
|
uniqueId = uniqueId()
|
|
256
262
|
|
|
263
|
+
/** Whether postal code validation rules are enabled (after first blur). */
|
|
264
|
+
postalCodeRulesEnabled = false
|
|
265
|
+
|
|
257
266
|
/** Called when component is created. */
|
|
258
267
|
created (): void {
|
|
259
268
|
// Initialize region field validation based on the starting country
|
|
@@ -420,7 +429,8 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
420
429
|
@Watch('addressLocal', { deep: true, immediate: true })
|
|
421
430
|
onAddressLocalChanged (): void {
|
|
422
431
|
this.emitAddress(this.addressLocal)
|
|
423
|
-
|
|
432
|
+
// form is valid only if postal code rules are enabled
|
|
433
|
+
this.emitValid(!this.$v.$invalid && this.postalCodeRulesEnabled)
|
|
424
434
|
}
|
|
425
435
|
|
|
426
436
|
/**
|
|
@@ -518,7 +528,7 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
518
528
|
this.addressLocal = newAddressLocal
|
|
519
529
|
|
|
520
530
|
// Validate the form, in case any fields are missing or incorrect.
|
|
521
|
-
Vue.nextTick(() =>
|
|
531
|
+
Vue.nextTick(() => this.validate())
|
|
522
532
|
}
|
|
523
533
|
|
|
524
534
|
getCountriesList (): Array<object> {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bcrs-shared-components/base-address",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.61",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@bcrs-shared-components/mixins": "^1.2.
|
|
8
|
+
"@bcrs-shared-components/mixins": "^1.2.2",
|
|
9
9
|
"lodash.uniqueid": "^4.0.1",
|
|
10
10
|
"vue": "^2.7.14",
|
|
11
11
|
"vuelidate": "0.6.2"
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"vue-property-decorator": "^9.1.2",
|
|
15
15
|
"vuelidate-property-decorators": "1.0.28"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "338d5c109363f2f5d55b914baf2eb24d396ddf15"
|
|
18
18
|
}
|