@@ -69,12 +69,11 @@ export default {
6969 }),
7070 methods: {
7171 submit : function () {
72- let grecaptcha_response = window .grecaptcha ? window .grecaptcha .getResponse (this .grecaptcha_id ) : ' -'
73- if (grecaptcha_response === ' ' ) {
72+ if (window .grecaptcha && ! this .$root .enquiry_data .grecaptcha_response ) {
7473 this .grecaptcha_missing = true
7574 return
7675 }
77- this . $set ( this . $root . enquiry_data , ' grecaptcha_response ' , grecaptcha_response)
76+
7877 if (this .contractor !== null ) {
7978 this .$set (this .$root .enquiry_data , ' contractor' , this .contractor .id )
8079 }
@@ -83,27 +82,36 @@ export default {
8382 },
8483 submission_complete : function () {
8584 this .submitted = true
86- }
87- },
88- created : function () {
85+ },
8986 /* istanbul ignore next */
90- if (this .$root .grecaptcha_key !== null ) {
91- let render_grecaptcha = () => {
87+ prepare_grecaptcha : function () {
88+ const grecaptcha_callback = (response ) => this .$set (this .$root .enquiry_data , ' grecaptcha_response' , response)
89+
90+ if (this .$root .grecaptcha_key === null ) {
91+ grecaptcha_callback (' -' )
92+ return
93+ }
94+
95+ const render_grecaptcha = () => {
9296 this .grecaptcha_id = window .grecaptcha .render (this .grecaptcha_container_id , {
93- ' sitekey' : this .$root .grecaptcha_key ,
97+ sitekey: this .$root .grecaptcha_key ,
98+ callback: grecaptcha_callback
9499 })
95100 }
96101 if (window .grecaptcha === undefined ) {
97102 window ._grecaptcha_loaded = render_grecaptcha
98103 add_script (' https://www.google.com/recaptcha/api.js?onload=_grecaptcha_loaded&render=explicit' )
99104 } else {
100- setTimeout ( render_grecaptcha, 50 )
105+ render_grecaptcha ( )
101106 }
102107 }
108+ },
109+ created : function () {
103110 this .$root .get_enquiry ()
104111 if (this .mode !== ' vanilla' ) {
105112 this .$root .ga_event (' enquiry-form' , ' loaded' , this .mode )
106113 }
114+ setTimeout (this .prepare_grecaptcha , 50 )
107115 },
108116}
109117 </script >
0 commit comments