Galen King
Galen King

Reputation: 772

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?

Upvotes: 2

Views: 584

Answers (2)

armchairdj
armchairdj

Reputation: 1070

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?

Upvotes: 1

fdsaas
fdsaas

Reputation: 714

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

Upvotes: 0

Related Questions