Permalink
Browse files

Make input classes more concise

  • Loading branch information...
1 parent ab19d71 commit d9a73f652f599b0056609f2875874ebd9e7f275b @nesquena committed Jan 7, 2009
Showing with 12 additions and 2 deletions.
  1. +11 −1 lib/semantic_fields_renderer.rb
  2. +1 −1 lib/semantic_form_builder.rb
@@ -147,12 +147,22 @@ def field_tag_item_options(element_name, input_type, options)
result_options = (options || {}).dup
result_options.reverse_merge!(:value => nil, :class => '', :id => element_name)
result_options[:label] ||= element_name.to_s.titleize
- result_options[:class] << " #{input_type}"
+ result_options[:class] << " #{input_type_to_class(input_type)}"
result_options
end
def method_missing(*args, &block)
@super.send(*args, &block)
end
+
+ private
+
+ # returns the class name based on input type
+ def input_type_to_class(input_type)
+ class_mappings = { :text_field => 'text', :radio_button => 'radio', :password_field => 'text',
+ :submit => 'submit', :image_submit => 'submit', :hidden_field => 'hidden',
+ :file_field => 'file', :check_box => 'checkbox' }
+ class_mappings[input_type.to_sym] || input_type
+ end
end
end
@@ -121,7 +121,7 @@ def radio_buttons(attribute, options)
html << @template.content_tag(:dd) do
returning choices_html = String.new do
options[:choices].each do |choice|
- choices_html << radio_button(attribute, choice.to_s) +
+ choices_html << radio_button(attribute, choice.to_s, :class => 'radio') +
@template.content_tag("label" , "#{choice.to_s.titleize}", :for => "#{object_name}_#{attribute}_#{choice.to_s}" )
end
end

0 comments on commit d9a73f6

Please sign in to comment.