aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb22
-rw-r--r--actionpack/lib/action_view/helpers/tags.rb1
-rw-r--r--actionpack/lib/action_view/helpers/tags/base.rb4
-rw-r--r--actionpack/lib/action_view/helpers/tags/check_box.rb4
-rw-r--r--actionpack/lib/action_view/helpers/tags/radio_button.rb35
5 files changed, 41 insertions, 25 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index c804c2646c..3b15e7097a 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -850,7 +850,7 @@ module ActionView
# # => <input type="radio" id="user_receive_newsletter_yes" name="user[receive_newsletter]" value="yes" />
# # <input type="radio" id="user_receive_newsletter_no" name="user[receive_newsletter]" value="no" checked="checked" />
def radio_button(object_name, method, tag_value, options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_radio_button_tag(tag_value, options)
+ ActionView::Helpers::Tags::RadioButton.new(object_name, method, self, tag_value, options).render
end
# Returns an input of type "search" for accessing a specified attribute (identified by +method+) on an object
@@ -959,7 +959,6 @@ module ActionView
attr_reader :object, :method_name, :object_name
DEFAULT_FIELD_OPTIONS = { "size" => 30 }
- DEFAULT_RADIO_OPTIONS = { }
def initialize(object_name, method_name, template_object, object = nil)
@object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
@@ -994,21 +993,6 @@ module ActionView
to_input_field_tag(field_type, options)
end
- def to_radio_button_tag(tag_value, options = {})
- options = DEFAULT_RADIO_OPTIONS.merge(options.stringify_keys)
- options["type"] = "radio"
- options["value"] = tag_value
- if options.has_key?("checked")
- cv = options.delete "checked"
- checked = cv == true || cv == "checked"
- else
- checked = self.class.radio_button_checked?(value(object), tag_value)
- end
- options["checked"] = "checked" if checked
- add_default_name_and_id_for_value(tag_value, options)
- tag("input", options)
- end
-
def to_boolean_select_tag(options = {})
options = options.stringify_keys
add_default_name_and_id(options)
@@ -1066,10 +1050,6 @@ module ActionView
object.send(method_name)
end
end
-
- def radio_button_checked?(value, checked_value)
- value.to_s == checked_value.to_s
- end
end
private
diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb
index 175bc5eb64..0ae7baffc6 100644
--- a/actionpack/lib/action_view/helpers/tags.rb
+++ b/actionpack/lib/action_view/helpers/tags.rb
@@ -9,6 +9,7 @@ module ActionView
autoload :FileField, 'action_view/helpers/tags/file_field'
autoload :TextArea, 'action_view/helpers/tags/text_area'
autoload :CheckBox, 'action_view/helpers/tags/check_box'
+ autoload :RadioButton, 'action_view/helpers/tags/radio_button'
end
end
end
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb
index 24f66f764e..c50c7716d4 100644
--- a/actionpack/lib/action_view/helpers/tags/base.rb
+++ b/actionpack/lib/action_view/helpers/tags/base.rb
@@ -24,6 +24,10 @@ module ActionView
private
+ def value(object)
+ object.send @method_name if object
+ end
+
def value_before_type_cast(object)
unless object.nil?
object.respond_to?(@method_name + "_before_type_cast") ?
diff --git a/actionpack/lib/action_view/helpers/tags/check_box.rb b/actionpack/lib/action_view/helpers/tags/check_box.rb
index 89aaad632c..55574e6f06 100644
--- a/actionpack/lib/action_view/helpers/tags/check_box.rb
+++ b/actionpack/lib/action_view/helpers/tags/check_box.rb
@@ -34,10 +34,6 @@ module ActionView
private
- def value(object)
- object.send @method_name if object
- end
-
def check_box_checked?(value)
case value
when TrueClass, FalseClass
diff --git a/actionpack/lib/action_view/helpers/tags/radio_button.rb b/actionpack/lib/action_view/helpers/tags/radio_button.rb
new file mode 100644
index 0000000000..3f6a360928
--- /dev/null
+++ b/actionpack/lib/action_view/helpers/tags/radio_button.rb
@@ -0,0 +1,35 @@
+module ActionView
+ module Helpers
+ module Tags
+ class RadioButton < Base #:nodoc:
+ def initialize(object_name, method_name, template_object, tag_value, options)
+ @tag_value = tag_value
+ super(object_name, method_name, template_object, options)
+ end
+
+ def render
+ options = @options.stringify_keys
+ options["type"] = "radio"
+ options["value"] = @tag_value
+
+ if options.has_key?("checked")
+ cv = options.delete "checked"
+ checked = cv == true || cv == "checked"
+ else
+ checked = radio_button_checked?(value(object))
+ end
+
+ options["checked"] = "checked" if checked
+ add_default_name_and_id_for_value(@tag_value, options)
+ tag("input", options)
+ end
+
+ private
+
+ def radio_button_checked?(value)
+ value.to_s == @tag_value.to_s
+ end
+ end
+ end
+ end
+end