Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed checkbox tag to work as expected

  • Loading branch information...
commit 59183fcd896041937896f574e1567c7068865c3d 1 parent a625033
@nesquena authored
View
0  .DS_Store 100644 → 100755
File mode changed
View
0  .gitignore 100644 → 100755
File mode changed
View
0  MIT-LICENSE 100644 → 100755
File mode changed
View
0  README 100644 → 100755
File mode changed
View
0  Rakefile 100644 → 100755
File mode changed
View
0  init.rb 100644 → 100755
File mode changed
View
20 lib/semantic_fields_renderer.rb 100644 → 100755
@@ -13,7 +13,6 @@ def initialize(template)
#
# - text_field_tag
# - password_field_tag
- # - check_box_tag
# - text_area_tag
#
# These were created dynamically in the method "self.create_field_element"
@@ -39,6 +38,21 @@ def file_field_tag(name, options = {})
end
end
+ # creates a check box tag which allows a boolean value to be toggled
+ # this will wrap the check box tag within a definition list
+ # in order to match the sematic style
+ def check_box_tag(name, options = {})
+ html = content_tag(:dt) do
+ content_tag(:label , "#{options.delete(:label)}:", :for => options[:id])
+ end
+
+ html << content_tag(:dd) do
+ checked = options.delete(:value).to_s != 'false'
+ @super.check_box_tag(name, "1", checked, options) +
+ @super.hidden_field_tag(name, "0")
+ end
+ end
+
# creates a select tag that is generated within a definition item
# for use within a definition form that has definition items for each field
#
@@ -97,7 +111,7 @@ def self.create_field_element(input_type)
end
html << content_tag(:dd) do
- html_tag = @super.send(field_tag_name, name, options.delete(:value), options)
+ html_tag = @super.send(field_tag_name, name, options.delete(:value).to_s, options)
options.delete(:error) ? ActionView::Base.field_error_proc.call(html_tag, @object) : html_tag
end
end
@@ -106,7 +120,7 @@ def self.create_field_element(input_type)
# for text, password, and check_boxes invoke the 'create_field_element' method to create
# appropriate helper methods for this renderer for each listed field type
#
- [ 'text_field', 'password_field', 'check_box', 'text_area' ].each { |field| self.create_field_element(field) }
+ [ 'text_field', 'password_field', 'text_area' ].each { |field| self.create_field_element(field) }
# given the element_name for the field and the options_hash will construct a hash
# filled with all pertinent information for creating a field_tag with the correct details
View
3  lib/semantic_form_builder.rb 100644 → 100755
@@ -197,7 +197,8 @@ def self.create_field_element(input_type_name)
raise "Semantic form fields must be contained within a fieldset!" unless @renderer
options = args.length > 0 ? args[0] : {} # grab the options hash
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}", :value => object_value, :error => @object.errors.on(attribute))
+ options.reverse_merge!(:label => attribute.to_s.titleize, :id => "#{object_name(:id)}_#{attribute}", :value => object_value.to_s)
+ options.reverse_merge!(:error => @object.errors.on(attribute)) if @object
@renderer.send(template_method, "#{object_name}[#{attribute}]", options)
end
end
View
0  lib/semantic_form_helpers.rb 100644 → 100755
File mode changed
View
0  tasks/semantic_form_builder_tasks.rake 100644 → 100755
File mode changed
View
0  test/semantic_form_builder_test.rb 100644 → 100755
File mode changed
View
0  uninstall.rb 100644 → 100755
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.