Skip to content

Commit

Permalink
wrapper_html should merge classes instead of overwriting them.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 18, 2009
1 parent cf6c4e9 commit df874ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/formtastic.rb
Expand Up @@ -80,12 +80,12 @@ def input(method, options = {})
options[:required] = method_required?(method, options[:required])
options[:as] ||= default_input_type(method)

html_class = [ options[:as], (options[:required] ? :required : :optional) ].join(' ')
html_class << ' error' if @object && @object.errors.on(method.to_s)
html_id = generate_html_id(method)
html_class = [ options[:as], (options[:required] ? :required : :optional) ]
html_class << 'error' if @object && @object.errors.on(method.to_s)

wrapper_html = options.delete(:wrapper_html) || {}
wrapper_html = { :id => html_id, :class => html_class }.merge(wrapper_html)
wrapper_html[:id] ||= generate_html_id(method)
wrapper_html[:class] = (html_class << wrapper_html[:class]).flatten.compact.join(' ')

if [:boolean_select, :boolean_radio].include?(options[:as])
::ActiveSupport::Deprecation.warn(":as => :#{options[:as]} is deprecated, use :as => :#{options[:as].to_s[8..-1]} instead", caller[3..-1])
Expand Down
19 changes: 18 additions & 1 deletion spec/formtastic_spec.rb
Expand Up @@ -653,9 +653,26 @@ def custom(arg1, arg2, options = {})
describe 'when provided' do
it 'should be passed down to the li tag' do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:id => :another_id, :class => :another_class}))
concat(builder.input(:title, :wrapper_html => {:id => :another_id}))
end
output_buffer.should have_tag("form li#another_id")
end

it 'should append given classes to li default classes' do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:class => :another_class}, :required => true))
end
output_buffer.should have_tag("form li.string")
output_buffer.should have_tag("form li.required")
output_buffer.should have_tag("form li.another_class")
end

it 'should allow classes to be an array' do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :wrapper_html => {:class => [ :my_class, :another_class ]}))
end
output_buffer.should have_tag("form li.string")
output_buffer.should have_tag("form li.my_class")
output_buffer.should have_tag("form li.another_class")
end
end
Expand Down

0 comments on commit df874ca

Please sign in to comment.