Permalink
Browse files

Added wrapper_html to customize li wrappers.

  • Loading branch information...
josevalim committed Apr 12, 2009
1 parent 4db8eec commit 11b668dca39f3503ee70b45b4778940e7de090fc
Showing with 36 additions and 9 deletions.
  1. +3 −3 README.textile
  2. +9 −6 lib/formtastic.rb
  3. +24 −0 spec/formtastic_spec.rb
View
@@ -156,13 +156,13 @@ If you want to customize the label text, or render some hint text below the fiel
<% end %>
</pre>
-If you want to customize html elements for any non button inputs you just need
-to specify the :input_html options hash.
+If you want to customize html elements for any non button inputs and the li
+wrapper you just need to specify the :input_html and :wrapper_html options hash.
<pre>
<% semantic_form_for @post do |form| %>
<%= form.input :title, :input_html => {:size => 60} %>
- <%= form.input :body %>
+ <%= form.input :body, :wrapper_html => { :class => 'body_wrapper' } %>
<%= form.input :created_at, :input_html => {:disabled => true} %>
<%= form.buttons %>
<% end %>
View
@@ -46,6 +46,7 @@ class SemanticFormBuilder < ActionView::Helpers::FormBuilder
# * :required - specify if the column is required (true) or not (false)
# * :hint - provide some text to hint or help the user provide the correct information for a field
# * :input_html - provide options that will be passed down to the generated input
+ # * :wrapper_html - provide options that will be passed down to the li wrapper
#
# Input Types:
#
@@ -85,20 +86,22 @@ def input(method, options = {})
method.to_s.send(@@label_str_method)
end
- 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])
- end
-
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)
+ wrapper_html = options.delete(:wrapper_html) || {}
+ wrapper_html = { :id => html_id, :class => html_class }.merge(wrapper_html)
+
+ 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])
+ end
+
list_item_content = @@inline_order.map do |type|
send(:"inline_#{type}_for", method, options)
end.compact.join("\n")
- return template.content_tag(:li, list_item_content, { :id => html_id, :class => html_class })
+ return template.content_tag(:li, list_item_content, wrapper_html)
end
# Creates an input fieldset and ol tag wrapping for use around a set of inputs. It can be
View
@@ -647,6 +647,30 @@ def custom(arg1, arg2, options = {})
end
end
+
+ describe ':wrapper_html option' do
+
+ 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}))
+ end
+ output_buffer.should have_tag("form li#another_id")
+ output_buffer.should have_tag("form li.another_class")
+ end
+ end
+
+ describe 'when not provided' do
+ it 'should use default id and class' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title))
+ end
+ output_buffer.should have_tag("form li#post_title_input")
+ output_buffer.should have_tag("form li.string")
+ end
+ end
+
+ end
end
describe ':as any type of input' do

0 comments on commit 11b668d

Please sign in to comment.