Skip to content

Commit

Permalink
Make input classes more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Jan 7, 2009
1 parent ab19d71 commit d9a73f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/semantic_fields_renderer.rb
Expand Up @@ -147,12 +147,22 @@ def field_tag_item_options(element_name, input_type, options)
result_options = (options || {}).dup result_options = (options || {}).dup
result_options.reverse_merge!(:value => nil, :class => '', :id => element_name) result_options.reverse_merge!(:value => nil, :class => '', :id => element_name)
result_options[:label] ||= element_name.to_s.titleize result_options[:label] ||= element_name.to_s.titleize
result_options[:class] << " #{input_type}" result_options[:class] << " #{input_type_to_class(input_type)}"
result_options result_options
end end


def method_missing(*args, &block) def method_missing(*args, &block)
@super.send(*args, &block) @super.send(*args, &block)
end 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
end end
2 changes: 1 addition & 1 deletion lib/semantic_form_builder.rb
Expand Up @@ -121,7 +121,7 @@ def radio_buttons(attribute, options)
html << @template.content_tag(:dd) do html << @template.content_tag(:dd) do
returning choices_html = String.new do returning choices_html = String.new do
options[:choices].each do |choice| 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}" ) @template.content_tag("label" , "#{choice.to_s.titleize}", :for => "#{object_name}_#{attribute}_#{choice.to_s}" )
end end
end end
Expand Down

0 comments on commit d9a73f6

Please sign in to comment.