diff --git a/src/components/AdditionalContacts.vue b/src/components/AdditionalContacts.vue index bf03a46..4d267e6 100644 --- a/src/components/AdditionalContacts.vue +++ b/src/components/AdditionalContacts.vue @@ -1,20 +1,24 @@ @@ -104,14 +194,51 @@ export default { mounted () { this.$refs.form.validate() }, + watch: { + addressModal (val) { + if (val) { + // decode address + let raw = this.$store.state.data.contacts.address.split('\n') + this.firstLine = raw[0] + if (raw.length === 3) { + this.secondLine = raw[1] + raw = raw[2].split('%postalsep%') + } else { + raw = raw[1].split('%postalsep%') + } + this.postalCode = raw[0] + this.city = raw[1] + } else { + // encode address + let encoded = '' + encoded += this.firstLine + if (this.secondLine !== '') { + encoded += '\n' + this.secondLine + } + encoded += '\n' + this.postalCode + '%postalsep%' + this.city + this.address = encoded.replace('%postalsep%', '') + this.$store.state.data.contacts.address = encoded + } + } + }, data: () => ({ formValid: false, + addressModal: false, rules: { website: [ v => v === '' || /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/gm.test(v) || "L'adresse web doit être valide" ], - address: [ - v => v.length < 200 || 'Maximum 200 caractères' + firstLine: [ + v => /^[0-9,-.A-Za-zÀàÂâÆzÉéÈèÊêËëÏïÎîÙùÛûÜüÇç' ]{2,40}$/gm.test(v) || "Ce champs doit être une ligne d'adresse valide" + ], + secondLine: [ + v => v === '' || /^[0-9,-.A-Za-zÀàÂâÆzÉéÈèÊêËëÏïÎîÙùÛûÜüÇç' ]{2,40}$/gm.test(v) || "Ce champs doit être une ligne d'adresse valide" + ], + postalCode: [ + v => /^[0-9]{2,6}$/gm.test(v) || 'Ce champs doit être un code postal valide' + ], + city: [ + v => v === '' || /^[0-9-A-Za-zÀàÂâÆzÉéÈèÊêËëÏïÎîÙùÛûÜüÇç' ]{2,40}$/gm.test(v) || "Ce champs doit être une ligne d'adresse valide" ], facebook: [ v => v === '' || /(http(s)?:\/\/)?(www\.)?facebook\.com\/(\S+){3,}/g.test(v) || 'Ce champs doit être une url facebook valide' @@ -122,7 +249,11 @@ export default { instagram: [ v => v === '' || /(http(s)?:\/\/)?(www\.)?instagram\.com\/(\S+){3,}/g.test(v) || 'Ce champs doit être une url instagram valide' ] - } + }, + firstLine: '', + secondLine: '', + postalCode: '', + city: '' }) }