javascript - Do not show autosuggest when list is active -


hey guys need help. added hidden list input search field. list opens when click input field , closes when click anywhere else besides list. instance if click on "montego bay" added input field , replaces current text in field.

however, have 2 questions:

  1. i have google maps autosuggestion working inside search field. how can allow google autosuggestion pop in search field if hidden list not active?

the google autosuggest script is:

$(function() { google.maps.event.adddomlistener(window,"load",function(){new google.maps.places.autocomplete(document.getelementbyid("hotelsplacesean"))}); }); var loading = false; 
  1. how can hide list if looses focus? (if set
$(".input").on("focusout", function() {   $(".suggest-content").addclass("hiddd"); }) 

,the list not add text search field when click on it, instead closes list before gets added.

input:

<input required id="hotelsplacesean" name="city" type="search" class="form input-lg rtl search-location deleteoutline opensuggest" placeholder="<?php echo trans('026'); ?>" value="<?php echo $themedata->selectedcity; ?>" required /> 

list:

<div class="suggest-div">          <span class="suggest-content hiddd">             <ul class="liststyle">                <li class="whylist"><b>popular destinations</b></li>                <li class="suggest"><a class="selectlink" href="">montego bay</a></li>                <li class="suggest"><a class="selectlink" href="">negril</a></li>                <li class="suggest"><a class="selectlink" href="">ocho rios</a></li>                <li class="suggest"><a class="selectlink" href="">kingston</a></li>                <li class="suggest" style="border-bottom:0px;"><a class="selectlink" href="">port antonio</a></li>             </ul>          </span>       </div> 

css:

<style>  a.selectlink {   padding-left: 10px;   padding-top: 10px;   padding-bottom: 10px;   display: block; }  a.selectlink:hover {   color: #fff; }  ul.liststyle {   margin-top: 0px; }  li.whylist {   padding-top: 10px;   padding-bottom: 10px;   background-color: #ddd;   color: #000;   padding-left: 10px;   font-size: 15px;   font-weight: 100;  }  li.suggest {   border-bottom: 1px solid #ddd;   font-size: 15px;   font-weight: 100; }  li.suggest:hover {   background-color: #515b62;   color: #fff; }  .suggest-div {   position: absolute;   width: 100%; }  span.suggest-content {   display: block;   background-color: #fff!important;   margin-top: 0px;   line-height: 1.2;   position: absolute;   width: 100%;   z-index: 999;  }  span.suggest-content:focus {  display: none; }  .hiddd {   display: none!important; }  .form {font-weight: 100!important;} </style> 

script:

<script type="text/javascript"> $(".selectlink").click(function(e) {     e.preventdefault();     $("#hotelsplacesean").val($(this).text()); });  $(".opensuggest").click(function() {     $(".suggest-content").toggleclass("hiddd");  });  $(".input").on("focusout", function() {   $(".suggest-content").addclass("hiddd"); })  </script> 

this screenshot of google autosuggest on list issue:

enter image description here

i grateful if me! in advance :)

1: can't without working example, , without knowing desired behavior. say: when "hidden list not active"? occurs when input not focused? surely that's not when want show google results? maybe want show google suggestions, if own script doesn't have suggestions???

2: suggested use timeout suggestions remain clickable.

$("input").on("focusout", function() {   settimeout(function() {     $(".suggest-content").addclass("hiddd");   }, 250); }); 

other ways be:

  • instead of click, use mousedown event fire on time. have check touch support

  • delegated event: create wrapper around input , dropdown, on wrapper listen propagated focusout. clicked suggestion event target. there stuff set input value.

here's working example , stuff play with: https://jsfiddle.net/m3r72hnx/


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -