0

I have a form_tag where I have implemented an autocomplete feature; when I submit the form the geolocation browser permission popup appears.

If I click on "don't allow", the form is then disabled. I would like to re-enable the form if the user click this. Any suggestions?

This is the current code:

<div id="tabs">
  <ul class="nav nav-tabs" id="prodTabs">
    <li class="active"><a href="#search">Search</a></li>
    <li><a href="#search_other"  data-toggle="tab">Search other</a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane" id="search_other">
      <%= form_tag search_path, :method => "get", id: "search-form" do %>
        <%= text_field_tag :search, params[:search], autofocus: true,
                            placeholder: "Enter keyword to search" %>
        <%= submit_tag "Search", name: nil, :style => "display: none;" %>
      <% end %>
    </div>
  </div>

<script>
  $(document).on("submit" ,"#search-form", function(e) {
      e.preventDefault();
      getGeoLocation();
  });
</script>

<script>
  function getGeoLocation() {
    navigator.geolocation.getCurrentPosition(setGeoCookie);
  }

  function setGeoCookie(position) {
    var cookie_val = position.coords.latitude + "|" + position.coords.longitude;
    document.cookie = "lat_lng=" + escape(cookie_val);
    $("#search-form").trigger('submit.rails');
  }
</script>

The form itself is inside a dynamic tab:

<script>
  $('#tabs').on('click','.tablink,#prodTabs a',function (e) {
    e.preventDefault();
    var url = $(this).attr("data-url");

    if (typeof url !== "undefined") {
      var pane = $(this), href = this.hash;

      // ajax load from data-url
      $(href).load(url,function(result){
        pane.tab('show');
      });
    } else {
      $(this).tab('show');
    }
  });
</script>
SRack
  • 11,495
  • 5
  • 47
  • 60
Theopap
  • 715
  • 1
  • 10
  • 33
  • Can you provide the code you’re working on, and explain what’s going on – possibly include screenshots too. Remember we can’t see your screen, so we have no idea what `don't allow` means and we don't know what a geolocation popup is! – Zoe Edwards Jan 26 '18 at 09:35
  • @Thomas Edwards I just edited my question! You will find more info now! – Theopap Jan 26 '18 at 09:49
  • 1
    So by “don’t allow” you mean the one in Google Chrome when it asks for your location? You might find https://stackoverflow.com/questions/6092400/is-there-a-way-to-check-if-geolocation-has-been-declined-with-javascript can help you. – Zoe Edwards Jan 26 '18 at 11:18

0 Answers0