From 7895699ef318c2c41294ca192335174aa0c882ce Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 14 Feb 2022 15:47:21 +0100 Subject: [PATCH] stronger client-side validation of addresses: also validate when initForm --- CHANGELOG.md | 1 + .../vuejs/Address/components/AddAddress.vue | 25 +++++++++++-------- .../AddAddress/AddressSelection.vue | 3 --- .../components/AddAddress/CitySelection.vue | 2 -- .../AddAddress/CountrySelection.vue | 2 -- .../vuejs/Address/components/EditPane.vue | 1 + 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc8917110..9dbff875f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to * [person]: AddPersons: allow creation of person or thirdparty depending on allowed types (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) * [person]: AddPersons: add suggestion of name when creating new person or thirdparty (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) * [main] Address: fix small bug: when modifying an address without street (isNoAddress), also check errors if street is an empty string as back-end change null value to empty string for street (and streetNumber) +* [main] Address: stronger client-side validation of addresses (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/449) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index e95bf9326..e351109a8 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -260,8 +260,7 @@ export default { editPane: false, datePane: false, loading: false, - success: false, - dirty: false + success: false }, errors: [], defaultz: { @@ -537,17 +536,19 @@ export default { checkErrors() { this.errors = []; - if (this.flag.dirty) { - if (this.entity.selected.country === null) { - this.errors.push("Un pays doit être sélectionné."); - } + if (this.entity.selected.country === null) { + this.errors.push("Un pays doit être sélectionné."); + } + if (this.entity.selected.city === null) { + this.errors.push("Une ville doit être sélectionnée."); + } else { if (Object.keys(this.entity.selected.city).length === 0) { this.errors.push("Une ville doit être sélectionnée."); } - if (!this.entity.selected.isNoAddress) { - if (this.entity.selected.address.street === null || this.entity.selected.address.street === '' || this.entity.selected.address.streetNumber === null || this.entity.selected.address.streetNumber === '') { - this.errors.push("Une adresse doit être sélectionnée."); - } + } + if (!this.entity.selected.isNoAddress) { + if (this.entity.selected.address.street === null || this.entity.selected.address.street === '' || this.entity.selected.address.streetNumber === null || this.entity.selected.address.streetNumber === '') { + this.errors.push("Une adresse doit être sélectionnée."); } } }, @@ -567,7 +568,7 @@ export default { this.entity.selected.country = this.context.edit ? this.entity.address.country : {}; this.entity.selected.postcode = this.context.edit ? this.entity.address.postcode : {}; - this.entity.selected.city = {}; + this.entity.selected.city = this.context.edit ? this.entity.address.postcode : {}; this.entity.selected.address = {}; this.entity.selected.address.street = this.context.edit ? this.entity.address.street: null; @@ -583,6 +584,8 @@ export default { this.entity.selected.writeNew.address = this.context.edit && this.entity.address.addressReference === null && this.entity.address.street.length > 0 this.entity.selected.writeNew.postcode = false // NB: this used to be this.context.edit, but think it was erroneous; console.log('!! just set writeNew.postcode to', this.entity.selected.writeNew.postcode); + + this.checkErrors(); }, /* diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressSelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressSelection.vue index ae134c88e..18e0caca3 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressSelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressSelection.vue @@ -111,11 +111,9 @@ export default { this.entity.selected.address.streetNumber = value.streetNumber; this.entity.selected.writeNew.address = false; this.updateMapCenter(value.point); - this.flag.dirty = true; this.checkErrors(); }, remove() { - this.flag.dirty = true; this.entity.selected.address = {}; this.checkErrors(); }, @@ -158,7 +156,6 @@ export default { this.entity.selected.address.street = addr.street; this.entity.selected.address.streetNumber = addr.number; this.entity.selected.writeNew.address = true; - this.flag.dirty = true; this.checkErrors(); } }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue index d0ff5c086..ca5d01b50 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue @@ -125,11 +125,9 @@ export default { if (value.center) { this.updateMapCenter(value.center); } - this.flag.dirty = true; this.checkErrors(); }, remove() { - this.flag.dirty = true; this.entity.selected.city = {}; this.checkErrors(); }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue index 09ba8421d..6e64b2985 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue @@ -51,7 +51,6 @@ export default { init() { if (this.value !== undefined) { this.selectCountry(this.value); - this.flag.dirty = false; } }, selectCountryByCode(countryCode) { @@ -67,7 +66,6 @@ export default { this.checkErrors(); }, remove() { - this.flag.dirty = true; this.entity.selected.country = null; this.checkErrors(); }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue index 5279880bc..503ca5b33 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue @@ -157,6 +157,7 @@ export default { set(value) { console.log('isNoAddress value', value); this.entity.selected.isNoAddress = value; + this.checkErrors(); }, get() { return this.entity.selected.isNoAddress;