如何在data-disable-with rails submit_tag上设置html [英] How to set html on data-disable-with to rails submit_tag

查看:200
本文介绍了如何在data-disable-with rails submit_tag上设置html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用bootstrap的RoR应用程序。我试图将fontawesome html图标标签应用于submit_tag帮助程序,但它似乎不受支持。当我点击提交时,禁用的内容只是显示为一个字符串,而不是被解释为html,虽然它为link_to助手。



这里是erb:

 <%= form_tag(/ home / search,方法:get,class:form-inline,role:搜索,remote:true)do%> 
< div class =form-group>
<%= text_field_tag(:term,nil,{:class =>form-control,data-html=> true,:value => @term})%>
< / div>
<%= submit_tagGo!,class:btn btn-transparent,role:button,'data-disable-with'=> < i class ='fa fa-spinner fa-spin'>< / i>正在搜索...。html_safe%>
<%end%>

下面是我点击提交时的样子:

它适用于link_to,但是我可以' t将text_field_tag的值传递给link_to,否则我会很满意这个解决方案。我真的宁愿避免自己编写.ajax方法,并使用javascript来操作按钮值。有关如何使用标准FormHelper标签解决此问题的任何建议?您应该尝试将 submit_tag 更改为 button_tag button_tag em>,像这样:

 <%= button_tagGo!,class:btn btn-transparent, 'data-disable-with'=> < i class ='fa fa-spinner fa-spin'>< / i>正在搜索...。html_safe%> 


I have a RoR app using bootstrap. I'm trying to apply the fontawesome html icon tag to a submit_tag helper, but it does not seem to be supported. When I click submit, the disable content just appears as a string instead of being interpreted to html, though it does for link_to helper.

Here's the erb:

    <%= form_tag("/home/search", method: "get", class: "form-inline", role: "search", remote: true) do %>
    <div class="form-group">
        <%= text_field_tag(:term, nil, {:class => "form-control", "data-html" => true, :value => @term}) %>
    </div>
    <%= submit_tag "Go!", class: "btn btn-transparent", role: "button", 'data-disable-with' => "<i class='fa fa-spinner fa-spin'></i> Searching...".html_safe %>    
 <% end %>

Here's what it comes out looking like when I click submit:

It works with link_to, but then I can't pass the value from the text_field_tag to link_to otherwise, I'd be happy with that solution. I'd really rather avoid writing the .ajax method myself and using javascript to manipulate button values. Any suggestions on how to solve this with the standard FormHelper tags? Many Thanks in advance.

解决方案

You should try to change submit_tag to button_tag, something like this:

<%= button_tag "Go!", class: "btn btn-transparent", 'data-disable-with' => "<i class='fa fa-spinner fa-spin'></i> Searching...".html_safe %>    

这篇关于如何在data-disable-with rails submit_tag上设置html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆