I am trying to create buttons ala Wufoo (Rediscovering the button element)
I would like to write the following code like the following:
<%form_tag search_path, :method => :get, :class => 'search' do %> <%=text_field_tag :search, params[:search] -%> <%=button_tag 'search', :name => nil-%> <%end%>
To generate the following HTML (instead of the input[type="submit"] tag)
<button type="submit" class="positive"> <img src="/images/icons/tick.png" alt=""/> Save </button>
Does a method exist already? Or should I roll my own helper?
Inside a <button> element you can put text (and tags like <i> , <b> , <strong> , <br> , <img> , etc.). That is not possible with a button created with the <input> element! Tip: Always specify the type attribute for a <button> element, to tell browsers what type of button it is.
The <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data. The form-handler is specified in the form's action attribute.
If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form . This will not broke any web standard.
submit : The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form> , or if the attribute is an empty or invalid value.
You could use content_tag to achieve this. It's the more railsy way of doing what you want. But it's longer than the raw HTML.
<% content_tag :button :type => :submit, :class => :positive do %> <%= image_tag "icons/tick.png"%> Save <% end %>
Which produces
<button type="submit" class="positive"> <img src="/images/icons/tick.png" alt="Tick"/> Save </button>
However using this as a starting point you should have no problem rolling your own robust helper, or abstracting it to a partial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With