HTML code inside buttons with simple_form

前端 未结 5 1295
情深已故
情深已故 2020-12-09 14:54

I\'m new to rails, and just found the simple_form gem. I installed it with bootstrap suport, but now I can\'t get this code to work the way I want it

<%=          


        
相关标签:
5条回答
  • 2020-12-09 15:16

    You can do this with the following code:

    = f.button :button, 'Send', data: { disable_with: "<i class='fi-heart'></i> Sending..." }
    

    Note that you want to use f.button instead of f.submit Also note that :button needs to be the first param to f.button

    0 讨论(0)
  • 2020-12-09 15:23

    One line example submit button in Rails with bootstrap btn class:

    <%= button_tag(type: 'submit', class: "btn btn-primary") do %> Save <% end %>
    
    0 讨论(0)
  • 2020-12-09 15:27

    Don't use content_tag. The following works:

      <%= button_tag(type: 'submit', class: "btn btn-primary") do %>
        <i class="icon-ok icon-white"></i> Save
      <% end %>
    
    0 讨论(0)
  • 2020-12-09 15:33

    In simple_form 3.0rc use :button button type (it passes your block to original ActiveView button helper):

    <%= f.button :button do %>
      <i class="icon-save"></i>
      Commit
    <% end %>
    

    Or write additional button wrapper.

    For additional info look into simple_form/form_builder.rb FormBuilder#button method.

    0 讨论(0)
  • 2020-12-09 15:41

    I think you can't do it with simple_form. But I have good news for you. You should be fine using rails helper along side with simple form.

    just do

    button_tag(type: 'submit', class: "btn btn-primary") do
      content_tag(:i, class: "icon-ok icon-white")
      "Save"
    end
    

    Not sure if this works, even the syntax but it should give you a hint

    0 讨论(0)
提交回复
热议问题