@Sacred133

Почему в localStorage не попадают данные из autocomplete?

Приветствую!

Сохраняю введенные данные в поле input в localStorage. Если вводить текстовые данные с клавиатуры или просто вставить скопированный текст, то эти данные в localStorage попадают. А вот если выбрать текст из подсказки, то в localStorage попадает только тот текст, который был набрал на клавиатуре, к примеру первая буква города, а выбранный город и подсказки, нет

Что не так?

<input type="text" name="input6" id="input6" value="" placeholder="Enter destination" class="large pac-target-input" autocomplete="off">

document.addEventListener('DOMContentLoaded', function() {
 let input2 = document.querySelector('[name="input6"].large');

 if (input2) {
   input2.value = localStorage.getItem("movingto") || "";

    input2.addEventListener('input', function() {
      localStorage.setItem("movingto", this.value);
    });
 }
});

const center = { lat: 50.064192, lng: -130.605469 };
const defaultBounds = {
  north: center.lat + 0.1,
  south: center.lat - 0.1,
  east: center.lng + 0.1,
  west: center.lng - 0.1,
};

const input5 = document.getElementById("input6");
const options = {
  bounds: defaultBounds,
  componentRestrictions: { country: "us" },
  fields: ["address_components", "geometry", "icon", "name"],
  strictBounds: false,
  types: ["establishment"],
};

const autocomplete2 = new google.maps.places.Autocomplete(input5, options);
  • Вопрос задан
  • 136 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы