带遥控器的表格:true 不适用于 turbolinks [英] Form with remote: true not working with turbolinks

查看:39
本文介绍了带遥控器的表格:true 不适用于 turbolinks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个表单并在其上设置了 remote: true.如果我直接刷新页面,它会起作用.如果我从菜单导航到所需的表单,则按钮什么也不做.

我尝试将data-no-turbolink="true"添加到菜单链接中,但仍然无法正常工作,可能是因为 turbolinks 5 不确定?

<%= form_for :location, url: get_inventory_path, remote: true do |f|%><div class="input-field col s12"><%= f.select :location_id, options_for_select(@locations.collect { |l|[l.station + ', ' + l.venue + ', ' + l.area + ', ' + l.city + ', ' + l.country, l.id] }, 1), {}, {id: 'location_select', class: "browser-default" } %>

<div class="card-action center-align"><%= f.submit "Go", class: "btn blue", data: { disable_with: "请稍候..." } %>

<%结束%>

我还添加了 Turbolinks 5 的新事件侦听器,这让事情变得更容易,但又一次..

$(document).on('turbolinks:load',function(){$(".button-collapse").sideNav();$('select').material_select();$('.dropdown-button').dropdown({下面起源:真实,约束宽度:假,对齐方式:正确"});$('.collapsible').collapsible();$('.tooltipped').tooltip({延迟: 50});});

欢迎提供任何线索!

解决方案

因此,在某些元素上禁用 turbolinks 似乎有效,但自 Turbolinks 5 以来它发生了变化,我在 turbolinks 5 文档中错过了它.供日后参考

文档中的示例

已禁用<div data-turbolinks="false"><a href="/">已禁用</a>

Rails 示例

<%= link_to "Overview", inventory_index_path, :"data-turbolinks"=>"false" %>

我希望这会有所帮助,但如果有人发现真正的问题,请让我们所有人都知道!

I have setup a form and set remote: true on it. While it works if i directly refresh the page. IF i navigate from menu to the desired form the button just does nothing.

I tried adding "data-no-turbolink="true" to the link of menu but still it doesn't work maybe because of turbolinks 5 not sure?

<%= form_for :location, url: get_inventory_path, remote: true do |f| %>
            <div class="input-field col s12">
              <%= f.select :location_id, options_for_select(@locations.collect { |l|
                [l.station + ', ' + l.venue + ', ' + l.area + ', ' + l.city + ', ' + l.country, l.id] }, 1), {}, { id: 'location_select', class: "browser-default" } %>
            </div>
        </div>
      </div>
      <div class="card-action center-align">
        <%= f.submit "Go", class: "btn blue", data: { disable_with: "Please wait..." } %>
      </div>
      <% end %>

also i added the new event listener of Turbolinks 5 which makes things easier but then again..

$(document).on('turbolinks:load',function(){
  $(".button-collapse").sideNav();
  $('select').material_select();
  $('.dropdown-button').dropdown({
    belowOrigin: true,
    constrain_width: false,
    alignment: "right"
  });
  $('.collapsible').collapsible();
  $('.tooltipped').tooltip({delay: 50});
});

any clues welcomed!

解决方案

So it seems disabling turbolinks on certain elements worked but it changed since Turbolinks 5 and i missed it on the turbolinks 5 documentation. For future reference

examples from documentation

<a href="/" data-turbolinks="false">Disabled</a>

<div data-turbolinks="false">
  <a href="/">Disabled</a>
</div>

Rails example

<%= link_to "Overview", inventory_index_path, :"data-turbolinks"=>"false" %>

I hope this helps but if anyone finds the real problem do let us all know!

这篇关于带遥控器的表格:true 不适用于 turbolinks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆