diff --git a/lib/formtastic/helpers/buttons_helper.rb b/lib/formtastic/helpers/buttons_helper.rb index 89d017bc1..55df22c28 100644 --- a/lib/formtastic/helpers/buttons_helper.rb +++ b/lib/formtastic/helpers/buttons_helper.rb @@ -246,6 +246,7 @@ def commit_button(*args) Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String) button_html = options.delete(:button_html) || {} + button_html[:id] ||= "#{@object_name}_submit" button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' ')) wrapper_html = options.delete(:wrapper_html) || {} @@ -253,7 +254,7 @@ def commit_button(*args) accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey) button_html = button_html.merge(:accesskey => accesskey) if accesskey - + template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html) end @@ -274,10 +275,10 @@ def commit_button_object_name else object_name = @object_name.to_s.send(label_str_method) end - + object_name end - + def commit_button_i18n_key if new_or_persisted_object? key = @object.persisted? ? :update : :create @@ -291,11 +292,11 @@ def commit_button_i18n_key def commit_button_wrapper_html_class ['commit', 'button'] # TODO: Add class reflecting on form action. end - + def new_or_persisted_object? @object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?)) end - + end end end \ No newline at end of file diff --git a/spec/helpers/commit_button_helper_spec.rb b/spec/helpers/commit_button_helper_spec.rb index a8d9d2ba9..eba019b72 100644 --- a/spec/helpers/commit_button_helper_spec.rb +++ b/spec/helpers/commit_button_helper_spec.rb @@ -29,7 +29,7 @@ end end - + describe 'when not persisted' do before do @@ -44,12 +44,12 @@ concat(builder.commit_button) end) end - + output_buffer.should have_tag('.commit input[@value="Submit Post"]') end end - - + + describe 'when used on any record' do before do @@ -62,7 +62,7 @@ it 'should render a commit li' do output_buffer.should have_tag('li.commit') end - + it 'should render a button li' do output_buffer.should have_tag('li.button') end @@ -204,11 +204,11 @@ } } end - + after do ::I18n.backend.reload! end - + it 'should render an input with localized label (I18n)' do with_config :i18n_lookups_by_default, true do ::I18n.backend.store_translations :en, @@ -225,7 +225,7 @@ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]}) end end - + it 'should render an input with anoptional localized label (I18n) - if first is not set' do with_config :i18n_lookups_by_default, true do concat(semantic_form_for(:post, :url => 'http://example.com') do |builder| @@ -427,7 +427,7 @@ def self.human_name end end - + describe ':wrapper_html option' do describe 'when provided' do @@ -457,14 +457,21 @@ def self.human_name end describe 'when not provided' do - it 'should use default id and class' do + it 'should use default class' do concat(semantic_form_for(@new_post) do |builder| concat(builder.commit_button('text')) end) output_buffer.should have_tag("form li.commit.button") end + + it 'should use default id' do + concat(semantic_form_for(@new_post) do |builder| + concat(builder.commit_button('text')) + end) + output_buffer.should have_tag("form li.commit.button input#post_submit") + end end end - + end