Class: FormProps::Inputs::CheckBox
- Defined in:
- lib/form_props/inputs/check_box.rb
Instance Method Summary collapse
-
#initialize(object_name, method_name, template_object, checked_value, unchecked_value, options) ⇒ CheckBox
constructor
A new instance of CheckBox.
- #input_checked?(options) ⇒ Boolean
- #render(flatten = false) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(object_name, method_name, template_object, checked_value, unchecked_value, options) ⇒ CheckBox
Returns a new instance of CheckBox.
6 7 8 9 10 |
# File 'lib/form_props/inputs/check_box.rb', line 6 def initialize(object_name, method_name, template_object, checked_value, unchecked_value, ) @checked_value = checked_value @unchecked_value = unchecked_value super(object_name, method_name, template_object, ) end |
Instance Method Details
#input_checked?(options) ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/form_props/inputs/check_box.rb', line 12 def input_checked?() if .has_key?(:checked) checked = .delete(:checked) checked == true || checked == "checked" else checked?(value) end end |
#render(flatten = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/form_props/inputs/check_box.rb', line 21 def render(flatten = false) = @options.stringify_keys [:type] = "checkbox" [:value] = @checked_value [:checked] = true if input_checked?() [:unchecked_value] = @unchecked_value || "" [:include_hidden] = .fetch(:include_hidden) { true } body_block = -> { if [:multiple] add_default_name_and_id_for_value(@checked_value, ) .delete(:multiple) else add_default_name_and_id() end input_props() } if flatten body_block.call else json.set!(sanitized_key) do body_block.call end end end |