Hi everybody,
I’m trying to integrate an address input field in Editor X and I used the solution offered by @massoudmaboudi (I’m very grateful that he took the time to share it with everybody).
https://www.editorxcommunity.com/forum/showcase/input-field-address-autocomplete-with-google-maps-in-editor-x
While it seems to be working because the repeater expands and collapses according to the number of suggestions that the API returns, it does not return any text suggestion. I made this video so it’s clearer :
And here is my code that is normally exactly what is suggested by Massoud. Do you have any idea of what I could be doing wrong ?
import { autocomplete } from ‘backend/gmapsapi’ ;
function getRandStr ( length = 10 ) {
return Math . random (). toString ( 20 ). substr ( 2 , length )
}
export function inputAddress_input ( event ) {
autocomplete ( $w ( ‘#inputAddress’ ). value )
. then (( res ) => {
let predictions = res . predictions ; // For simplicity we put the predictions in a new variable
let suggestions = ; // We should create an empty array for the suggestions
predictions . forEach ( function ( prediction ) {
let item = { “_id” : getRandStr (), “address” : prediction . description };
suggestions . push ( item );
});
$w ( “#repeaterSuggestions” ). data = ; // clear the repeater contents
$w ( “#repeaterSuggestions” ). data = suggestions ; // add the new suggestions to the repeater
$w ( “#repeaterSuggestions” ). expand (); // Repeater is full now, let’s show it.
})
}
export function repeaterSuggestions_itemReady ( $item , itemData , index ) {
$item ( “#text1” ). text = itemData . address ;
$item ( “#text1” ). onClick (( event ) => {
$w ( ‘#inputAddress’ ). value = $item ( “#text1” ). text
$w ( ‘#repeaterSuggestions’ ). collapse ()
. catch ( ( error ) => {
console . log ( error );
});
}
)}
Thank you all in advance, I’ve been struggling with this for days!