Class: FormProps::Inputs::RadioButton
- Defined in:
- lib/form_props/inputs/radio_button.rb
Instance Method Summary collapse
-
#initialize(object_name, method_name, template_object, tag_value, options) ⇒ RadioButton
constructor
A new instance of RadioButton.
- #input_checked?(options) ⇒ Boolean
- #render(flatten = false) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(object_name, method_name, template_object, tag_value, options) ⇒ RadioButton
Returns a new instance of RadioButton.
6 7 8 9 |
# File 'lib/form_props/inputs/radio_button.rb', line 6 def initialize(object_name, method_name, template_object, tag_value, ) @tag_value = tag_value super(object_name, method_name, template_object, ) end |
Instance Method Details
#input_checked?(options) ⇒ Boolean
11 12 13 14 15 16 17 18 |
# File 'lib/form_props/inputs/radio_button.rb', line 11 def input_checked?() if .has_key?(:checked) checked = .delete(:checked) checked == true || checked == "checked" else checked?(value) end end |
#render(flatten = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/form_props/inputs/radio_button.rb', line 20 def render(flatten = false) @options[:type] = "radio" @options[:value] = @tag_value @options[:checked] = true if input_checked?(@options) body_block = -> { add_default_name_and_id_for_value(@tag_value, @options) input_props(@options) } if flatten body_block.call else json.set!(sanitized_key) do body_block.call end end end |