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>