简体   繁体   中英

Get formtastic to create <button> fields rather than <input>?

I am wondering how I can get formtastic to render submit buttons as:

<button … >

Rather than:

<input type="submit" … >

Any ideas?

I'm not a contributor, but I'd guess it's because of the richer visual rendering possibilities of the button element. The only problem with the button element is supporting older versions of IE (notably IE6) and trying to pass name/value pairs through the button. If you don't need to support IE6, the button element works great, implicitly submits when clicked, passes name/value pairs with the request, and can contain arbitrary HTML.

Good discussion of the pros/cons here:

<button> vs. <input type="button" />. Which to use?

This may be what you are looking for.

This is an excerpt from formtastic/lib/formtastic/actions/button_action.rb on Github :

#   <%= semantic_form_for(@post) do |f| %>
#     <%= f.actions do %>
#       <%= f.action :reset, :as => :button %>
#       <%= f.action :submit, :as => :button %>
#     <% end %>
#   <% end %>
#
#   <form...>
#     <fieldset class="actions">
#       <ol>
#         <li class="action button_action" id="post_reset_action">
#           <button type="reset" value="Reset">
#         </li>
#         <li class="action button_action" id="post_submit_action">
#           <button type="submit" value="Create Post">
#         </li>
#       </ol>
#     </fieldset>
#   </form>

And if this doesn't do exactly what you are looking for, you can always fork Formtastic!

References

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM