79610613

Date: 2025-05-07 13:14:13
Score: 1.5
Natty:
Report link

Okay, I found examples of working autocompletes with the forward geocoder which fills out a form with the city, postal code and address.

import placekitAutocomplete from '@placekit/autocomplete-js';

import 'shared/global.css'; // load tailwindcss
import '@placekit/autocomplete-js/dist/placekit-autocomplete.css';

// instantiate PlaceKit Autocomplete JS
const pka = placekitAutocomplete(import.meta.env.VITE_PLACEKIT_API_KEY, {
  target: '#placekit-input',
});

// inject values when user picks an address
const form = document.querySelector('#form');
pka.on('pick', (value, item) => {
  for (const name of ['city', 'zipcode', 'country']) {
    form.querySelector(`input[name="${name}"]`).value = [].concat(item[name]).join(',');
  }
});

https://github.com/placekit/examples/tree/main/examples/autocomplete-js-address-form

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Han Solo