11<template >
22 <div class =" tcs-enquiry" >
3- <div class =" tcs-submitted" v-if =" submitted" v-html =" $root.get_text('enquiry_submitted_thanks', {}, true)" ></div >
3+ <div class =" tcs-submitted" v-if =" submitted" >
4+ <div v-if =" ismodal" v-html =" $root.get_text('enquiry_modal_submitted_thanks', {}, true)" ></div >
5+ <div v-else v-html =" $root.get_text('enquiry_submitted_thanks', {}, true)" ></div >
6+ </div >
47 <div v-else >
58 <div v-if =" contractor" class =" tcs-centre" v-html =" $root.get_text('contractor_enquiry_message', {contractor_name: contractor.name}, true)" >
69 </div >
1316 <div v-for =" field in attribute_fields" >
1417 <tcs-input :field =" field" prefix =" attributes" ></tcs-input >
1518 </div >
19+
20+ <div :id =" grecaptcha_container_id" class =" grecaptcha" ></div >
21+ <div v-if =" grecaptcha_missing" class =" error-msg" >
22+ {{ $root.get_text('grecaptcha_missing') }}
23+ </div >
24+
1625 <div class =" tcs-field tcs-submit" >
1726 <button type =" submit" >
1827 {{ $root.config.submit_enquiry }}
2534
2635<script >
2736import input from ' ./input.vue'
37+ import {add_script } from ' ../utils'
2838
2939export default {
3040 props: {
3141 contractor: {
3242 type: Object ,
3343 default: null ,
3444 },
45+ ismodal: {
46+ type: Boolean ,
47+ default: false ,
48+ },
3549 },
3650 components: {
3751 ' tcs-input' : input
@@ -45,10 +59,19 @@ export default {
4559 }
4660 },
4761 data : () => ({
48- submitted: false
62+ submitted: false ,
63+ grecaptcha_missing: false ,
64+ grecaptcha_container_id: ' grecaptcha_' + Math .random ().toString (36 ).substring (2 , 10 ),
65+ grecaptcha_id: null ,
4966 }),
5067 methods: {
5168 submit : function () {
69+ let grecaptcha_response = window .grecaptcha ? window .grecaptcha .getResponse (this .grecaptcha_id ) : ' -'
70+ if (grecaptcha_response === ' ' ) {
71+ this .grecaptcha_missing = true
72+ return
73+ }
74+ this .$set (this .$root .enquiry_data , ' grecaptcha_response' , grecaptcha_response)
5275 if (this .contractor !== null ) {
5376 this .$set (this .$root .enquiry_data , ' contractor' , this .contractor .id )
5477 }
@@ -59,6 +82,20 @@ export default {
5982 }
6083 },
6184 created : function () {
85+ /* istanbul ignore next */
86+ if (this .$root .grecaptcha_key !== null ) {
87+ let render_grecaptcha = () => {
88+ this .grecaptcha_id = window .grecaptcha .render (this .grecaptcha_container_id , {
89+ ' sitekey' : this .$root .grecaptcha_key ,
90+ })
91+ }
92+ if (window .grecaptcha === undefined ) {
93+ window ._grecaptcha_loaded = render_grecaptcha
94+ add_script (' https://www.google.com/recaptcha/api.js?onload=_grecaptcha_loaded&render=explicit' )
95+ } else {
96+ setTimeout (render_grecaptcha, 50 )
97+ }
98+ }
6299 this .$root .get_enquiry ()
63100 },
64101}
@@ -84,11 +121,19 @@ form.tcs {
84121}
85122
86123.tcs-submit {
87- text-align : right ;
124+ text-align : center ;
88125 button {
89126 @extend .tcs-button ;
90127 font-size : 17px ;
91128 padding : 10px 12px ;
92129 }
93130}
131+
132+ .grecaptcha > div {
133+ margin : 0 auto ;
134+ }
135+ .error-msg {
136+ color : darkred ;
137+ text-align : center ;
138+ }
94139 </style >
0 commit comments