From 2aa588037adc98cd5585099ab56a3f4fba67ff8f Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 3 Nov 2021 13:51:15 +0100 Subject: [PATCH] location: client side validation --- .../vuejs/Activity/components/Location.vue | 2 +- .../components/Location/NewLocation.vue | 61 ++++++++++++++----- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue index 30a1c5bd9..c8d1472bd 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -66,7 +66,7 @@ export default { })) }, customLabel(value) { - return `${value.locationType.title.fr} ${value.name}`; + return `${value.locationType.title.fr} ${value.name ? value.name : ''}`; } } } diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue index 2db928b3b..1b563d2a2 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue @@ -30,7 +30,7 @@
@@ -46,10 +46,11 @@ :context="addAddress.context" :options="addAddress.options" :addressChangedCallback="submitNewAddress" + v-if="showAddAddress" ref="addAddress"> -
+
@@ -57,7 +58,7 @@
-
+
@@ -166,7 +167,25 @@ export default { }, hasPhonenumber1() { return this.selected.phonenumber1 !== null && this.selected.phonenumber1 !== ""; - } + }, + showAddAddress() { + let cond = false; + if (this.selected.type) { + if (this.selected.type.addressRequired !== 'never') { + cond = true; + } + } + return cond; + }, + showContactData() { + let cond = false; + if (this.selected.type) { + if (this.selected.type.contactData !== 'never') { + cond = true; + } + } + return cond; + }, }, mounted() { this.getLocationTypesList(); @@ -174,18 +193,24 @@ export default { methods: { checkForm() { let cond = true; - console.log('check form'); this.errors = []; - console.log(this.selected.type) - if (this.selected.type) { - //TODO conditional requirements for field - //if (this.selected.type.addressRequired = 'required') ... - cond = true; - } else { + if (!this.selected.type) { this.errors.push('Type de localisation requis'); cond = false; + } else { + if (this.selected.type.addressRequired === 'required' && !this.selected.addressId) { + this.errors.push('Adresse requise'); + cond = false; + } + if (this.selected.type.contactData === 'required' && !this.selected.phonenumber1) { + this.errors.push('Numéro de téléphone requis'); + cond = false; + } + if (this.selected.type.contactData === 'required' && !this.selected.email) { + this.errors.push('Adresse email requise'); + cond = false; + } } - return cond; }, getLocationTypesList() { @@ -204,17 +229,21 @@ export default { let body = { type: 'location', name: this.selected.name, - address: { - id: this.selected.addressId - }, locationType: { - id: this.selected.type, + id: this.selected.type.id, type: 'location-type' }, phonenumber1: this.selected.phonenumber1, phonenumber2: this.selected.phonenumber2, email: this.selected.email, }; + if (this.selected.addressId) { + body = Object.assign(body, { + address: { + id: this.selected.addressId + } + }); + } postLocation(body).then(location => new Promise(resolve => { console.log('postLocation', location); this.locations.push(location);