Rails形式重新启用

时间:2018-01-26 09:28:36

标签: javascript jquery ruby-on-rails

我有form_tag我已实施自动填充功能;当我提交表单时,会出现地理位置浏览器权限弹出窗口。

如果我点击"不允许",则表单将被禁用。如果用户点击此表单,我想重新启用该表单。有什么建议吗?

这是当前的代码:

<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>

表单本身位于动态标签内:

<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>

0 个答案:

没有答案