Permalink
Browse files

Added button_html to customize buttons.

  • Loading branch information...
1 parent 11b668d commit 8cbbf04718829f9603b5db1230813ab29ae7ebb5 @josevalim josevalim committed Apr 12, 2009
Showing with 16 additions and 3 deletions.
  1. +2 −0 README.textile
  2. +4 −3 lib/formtastic.rb
  3. +10 −0 spec/formtastic_spec.rb
View
@@ -168,6 +168,8 @@ wrapper you just need to specify the :input_html and :wrapper_html options hash.
<% end %>
</pre>
+To customize buttons, :button_html is available.
+
Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
<pre>
View
@@ -281,9 +281,10 @@ def buttons(*args, &block)
#
# <%= form.commit_button "Go" %> => <input name="commit" type="submit" value="Go" />
#
- def commit_button(value=nil, options = {})
- value ||= save_or_create_button_text
- template.content_tag(:li, template.submit_tag(value), :class => "commit")
+ def commit_button(value=nil, options={})
+ value ||= save_or_create_button_text
+ button_html = options.delete(:button_html) || {}
+ template.content_tag(:li, self.submit(value, button_html), :class => "commit")
end
# A thin wrapper around #fields_for to set :builder => Formtastic::SemanticFormBuilder
View
@@ -2346,6 +2346,16 @@ def custom(arg1, arg2, options = {})
output_buffer.should have_tag('li.commit input[@name="commit"]')
end
+ it 'should pass options given in :button_html to the button' do
+ @new_post.stub!(:new_record?).and_return(false)
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button('text', :button_html => {:class => 'my_class', :id => 'my_id'}))
+ end
+
+ output_buffer.should have_tag('li.commit input#my_id')
+ output_buffer.should have_tag('li.commit input.my_class')
+ end
+
end
describe 'when used on an existing record' do

0 comments on commit 8cbbf04

Please sign in to comment.