@bcrs-shared-components/base-address 2.0.59 → 2.1.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/BaseAddress.vue +47 -35
- 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 -->
|
|
@@ -59,6 +46,7 @@
|
|
|
59
46
|
<v-form
|
|
60
47
|
v-if="editing"
|
|
61
48
|
ref="addressForm"
|
|
49
|
+
v-model="addressFormValid"
|
|
62
50
|
name="address-form"
|
|
63
51
|
lazy-validation
|
|
64
52
|
>
|
|
@@ -148,8 +136,9 @@
|
|
|
148
136
|
filled
|
|
149
137
|
class="item postal-code"
|
|
150
138
|
:label="postalCodeLabel"
|
|
151
|
-
:rules="[...rules.postalCode, ...spaceRules]"
|
|
139
|
+
:rules="postalCodeRulesEnabled ? [...rules.postalCode, ...spaceRules] : []"
|
|
152
140
|
@input="addressLocal.postalCode = addressLocal.postalCode?.toUpperCase()"
|
|
141
|
+
@blur="postalCodeRulesEnabled = true"
|
|
153
142
|
/>
|
|
154
143
|
</div>
|
|
155
144
|
<div class="form__row">
|
|
@@ -175,6 +164,7 @@ import { Component, Mixins, Emit, Prop, Watch } from 'vue-property-decorator'
|
|
|
175
164
|
import { Validations } from 'vuelidate-property-decorators'
|
|
176
165
|
import { uniqueId } from 'lodash'
|
|
177
166
|
import { ValidationMixin, CountriesProvincesMixin } from '@bcrs-shared-components/mixins'
|
|
167
|
+
import { FormIF } from '@bcrs-shared-components/interfaces'
|
|
178
168
|
|
|
179
169
|
/**
|
|
180
170
|
* The component for displaying and editing an address.
|
|
@@ -188,7 +178,7 @@ import { ValidationMixin, CountriesProvincesMixin } from '@bcrs-shared-component
|
|
|
188
178
|
export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvincesMixin) {
|
|
189
179
|
// Refs
|
|
190
180
|
$refs!: {
|
|
191
|
-
addressForm:
|
|
181
|
+
addressForm: FormIF
|
|
192
182
|
}
|
|
193
183
|
|
|
194
184
|
/**
|
|
@@ -237,12 +227,29 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
237
227
|
@Prop({ default: false })
|
|
238
228
|
readonly isInactive: boolean
|
|
239
229
|
|
|
230
|
+
/** Called, possibly externally, to validate all registered form inputs. */
|
|
231
|
+
public validate (): any {
|
|
232
|
+
this.postalCodeRulesEnabled = true
|
|
233
|
+
return this.$refs.addressForm.validate()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Called, possibly externally, to reset validation of all registered form inputs and clear their values. */
|
|
237
|
+
public reset (): any {
|
|
238
|
+
this.postalCodeRulesEnabled = false
|
|
239
|
+
return this.$refs.addressForm.reset()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Called, possibly externally, to reset validation of all registered form inputs without modifying their values. */
|
|
243
|
+
public resetValidation (): any {
|
|
244
|
+
return this.$refs.addressForm.resetValidation()
|
|
245
|
+
}
|
|
246
|
+
|
|
240
247
|
/** When country changes, resets fields. */
|
|
241
248
|
onCountryChange () {
|
|
242
249
|
this.addressLocal['addressRegion'] = ''
|
|
243
250
|
this.addressLocal['postalCode'] = ''
|
|
244
251
|
// clear any existing validation errors
|
|
245
|
-
this
|
|
252
|
+
this.resetValidation()
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
/** A local (working) copy of the address, to contain the fields edited by the component (ie, the model). */
|
|
@@ -254,6 +261,12 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
254
261
|
/** A unique id for this instance of this component. */
|
|
255
262
|
uniqueId = uniqueId()
|
|
256
263
|
|
|
264
|
+
/** Whether address form is valid. */
|
|
265
|
+
addressFormValid = false
|
|
266
|
+
|
|
267
|
+
/** Whether postal code validation rules are enabled (ie, after first blur or validate call). */
|
|
268
|
+
postalCodeRulesEnabled = false
|
|
269
|
+
|
|
257
270
|
/** Called when component is created. */
|
|
258
271
|
created (): void {
|
|
259
272
|
// Initialize region field validation based on the starting country
|
|
@@ -363,18 +376,8 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
363
376
|
return this.createVuetifyRulesObject('addressLocal')
|
|
364
377
|
}
|
|
365
378
|
|
|
366
|
-
/** Emits an update message for the address prop, so that the caller can ".sync" with it. */
|
|
367
|
-
@Emit('update:address')
|
|
368
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
369
|
-
emitAddress (address: object): void { }
|
|
370
|
-
|
|
371
|
-
/** Emits the validity of the address entered by the user. */
|
|
372
|
-
@Emit('valid')
|
|
373
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
374
|
-
emitValid (valid: boolean): void { }
|
|
375
|
-
|
|
376
379
|
/**
|
|
377
|
-
* Watches changes to the Schema object, so that if the parent changes the data
|
|
380
|
+
* Watches for changes to the Schema object, so that if the parent changes the data then
|
|
378
381
|
* the working copy of it is updated.
|
|
379
382
|
*/
|
|
380
383
|
@Watch('schema', { deep: true, immediate: true })
|
|
@@ -383,7 +386,7 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
383
386
|
}
|
|
384
387
|
|
|
385
388
|
/**
|
|
386
|
-
* Watches changes to the Address object, so that if the parent changes the data
|
|
389
|
+
* Watches for changes to the Address object, so that if the parent changes the data then
|
|
387
390
|
* the working copy of it is updated.
|
|
388
391
|
*/
|
|
389
392
|
@Watch('address', { deep: true, immediate: true })
|
|
@@ -392,7 +395,7 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
392
395
|
}
|
|
393
396
|
|
|
394
397
|
/**
|
|
395
|
-
* Watches changes to the Address Country and updates the schema accordingly.
|
|
398
|
+
* Watches for changes to the Address Country and updates the schema accordingly.
|
|
396
399
|
*/
|
|
397
400
|
@Watch('addressCountry')
|
|
398
401
|
onAddressCountryChanged (): void {
|
|
@@ -414,13 +417,22 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
414
417
|
}
|
|
415
418
|
|
|
416
419
|
/**
|
|
417
|
-
* Watches changes to the
|
|
418
|
-
*
|
|
420
|
+
* Watches for changes to the local address object, to catch any changes to the fields within the address.
|
|
421
|
+
* Emits an update message for the address prop, so that the caller can ".sync" with it.
|
|
422
|
+
* If this causes the form to become valid or invalid then another watcher will handle that.
|
|
419
423
|
*/
|
|
420
424
|
@Watch('addressLocal', { deep: true, immediate: true })
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.
|
|
425
|
+
@Emit('update:address')
|
|
426
|
+
onAddressLocalChanged (): any {
|
|
427
|
+
return this.addressLocal
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Watches for changes to the address form validity and emits the updated state. */
|
|
431
|
+
@Watch('addressFormValid')
|
|
432
|
+
@Emit('valid')
|
|
433
|
+
onAddressFormValidChanged (): boolean {
|
|
434
|
+
// form is valid only if postal code rules are enabled
|
|
435
|
+
return (!this.$v.$invalid && this.postalCodeRulesEnabled)
|
|
424
436
|
}
|
|
425
437
|
|
|
426
438
|
/**
|
|
@@ -518,7 +530,7 @@ export default class BaseAddress extends Mixins(ValidationMixin, CountriesProvin
|
|
|
518
530
|
this.addressLocal = newAddressLocal
|
|
519
531
|
|
|
520
532
|
// Validate the form, in case any fields are missing or incorrect.
|
|
521
|
-
Vue.nextTick(() =>
|
|
533
|
+
Vue.nextTick(() => this.validate())
|
|
522
534
|
}
|
|
523
535
|
|
|
524
536
|
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.1.0",
|
|
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": "b76f47d6b97b9caf02baa98461dfcf5dc9526f7c"
|
|
18
18
|
}
|