Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/ptzn/semantic_form_builder

  • Loading branch information...
commit 98fc8a8bf8f3593e3028842583abd359ee6e4917 2 parents 5c6ed2f + 0bb67db
@nesquena authored
Showing with 20 additions and 3 deletions.
  1. +1 −1  lib/semantic_fields_renderer.rb
  2. +19 −2 lib/semantic_form_builder.rb
View
2  lib/semantic_fields_renderer.rb
@@ -50,7 +50,7 @@ def check_box_tag(name, options = {})
options[:class] = append_class_name(options[:class], 'checkbox')
html << content_tag(:dd) do
checked = options.delete(:value).to_s != 'false'
- @super.hidden_field_tag(name, "0") +
+ @super.hidden_field_tag(name, "0", :id => "#{options[:id]}_hidden") +
@super.check_box_tag(name, "1", checked, options)
end
end
View
21 lib/semantic_form_builder.rb
@@ -149,6 +149,8 @@ def image_submit_button(image_file, options={})
#
# ex:
# f.radio_buttons :gender, :choices => [ :male, :female ]
+ # also you can provide array of arrays to use different option value and caption
+ # f.radio_buttons :gender, :choices => [ ['Male', 1], ['Female', 2] ]
#
def radio_buttons(attribute, options)
caption = (options.delete(:label) || attribute.to_s.titleize).gsub(' ', '&nbsp;') + ":"
@@ -156,12 +158,27 @@ 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, :class => 'radio') +
- @template.content_tag("label" , "#{choice.to_s.titleize}", :for => "#{object_name}_#{attribute}_#{choice.to_s}" )
+ label, value = choice.is_a?(Array) ? [choice.first, choice.last.to_s] : [choice.to_s.titleize, choice.to_s]
+ choices_html << radio_button(attribute, value, :class => 'radio') +
+ @template.content_tag("label" , label, :for => "#{object_name}_#{attribute}_#{value}" )
end
end
end
end
+
+ # creates a select control that is generated within a definition item
+ # for use within a definition form that has definition items for each field
+ #
+ # <dt><label for="user[group]">Group</label></dt>
+ # <dd><select id="user_group" name="user[group]">...</select></dd>
+ #
+ # ex: f.select(:group, @option_values)
+ #
+ def select(attribute, choices, options = {})
+ object_value = @object ? @object.send(attribute) : nil # grab the object's value
+ options.reverse_merge!(:label => attribute.to_s.titleize, :id => "#{object_name(:id)}_#{attribute}")
+ @renderer.select_tag("#{object_name}[#{attribute}]", @template.options_for_select(choices, object_value), options)
+ end
# creates a calendar date select object using the "calendar_date_select" plugin
# this was added in order to wrap the control with the proper definition item
Please sign in to comment.
Something went wrong with that request. Please try again.