2017-04-16 54 views
1
function wnw_set_google_autocomplete_my(){ 
    jQuery(gaaf_fields_my).each(function(){ 

     var autocomplete_my= new google.maps.places.Autocomplete(
     /** @type {HTMLInputElement} */(this), 
     { types: ['geocode'] }); 
     // When the user selects an address from the dropdown, 
     // populate the address fields in the form. 

    }); 
} 
jQuery(window).load(function(){ 
    wnw_set_google_autocomplete_my(); 
}); 

鏈接:http://35.154.204.251/contact/谷歌自動完成Places API的錯誤InvalidValueError

我已經在WordPress安裝了谷歌的自動完成地方API和我在控制檯越來越InvalidValueError,我無法找出問題,因爲每一件事情是對我看來很好。

回答

2

查看變量gaaf_fields_my的值。當我把一個破發點,我可以看到這個變量具有以下值

" [name="input_2"], [name="demo"], #input_2_2, #demo, .address, .demo"

的問題是,jQuery(gaaf_fields_my)回報作爲第一元素具有類「地址」,是不是<input>一個<li>元素。這會導致自動完成構造函數中的一個異常,該構造函數需要輸入元素作爲參數,但您嘗試在<li>上初始化它。

enter image description here

你應該申請一個更好的選擇或調用自動完成構造函數之前檢查jQuery的循環內的元素的標籤名稱:

function wnw_set_google_autocomplete_my(){ 
    jQuery(gaaf_fields_my).each(function(){ 

     if (this.tagName.toLowerCase() === 'input') { 

      var autocomplete_my= new google.maps.places.Autocomplete(
       /** @type {HTMLInputElement} */(this), 
       { types: ['geocode'] }); 

     } 
    }); 
} 
+0

由於做工精細:) – himanshuahuja

+0

順便說一句什麼突破型點你用過的 – himanshuahuja