Class: SwitchCheckboxInput
- Inherits:
-
SimpleForm::Inputs::BooleanInput
- Object
- SimpleForm::Inputs::BooleanInput
- SwitchCheckboxInput
- Defined in:
- lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb
Overview
SwitchCheckboxInput is a custom input type for SimpleForm that renders a checkbox as an optics (v0.5.0+) switch control
Options:
:small - renders a smaller switch control
:label_after_input - renders the label after the switch control
:wrapper - the wrapper to use for this input, defaults to :inline_switch_wrapper. :switch_wrapper is also available.
Usage: <%= f.input :my_field, as: :switch_checkbox %> <%= f.input :my_field, as: :switch_checkbox, small: true %> <%= f.input :my_field, as: :switch_checkbox, disabled: true %> <%= f.input :my_field, as: :switch_checkbox, label_after_input: true %> <%= f.input :my_field, as: :switch_checkbox, wrapper: :switch_wrapper %>
Instance Method Summary collapse
Instance Method Details
#input(wrapper_options = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb', line 17 def input( = nil) = (, ) switch_group = template.content_tag(:div, class: "switch #{'switch--small' if [:small]}") do if include_hidden? build_check_box(unchecked_value, ) else build_check_box_without_hidden_field() end + label() end if [:label_after_input] switch_group + label() else label() + switch_group end end |
#input_html_classes ⇒ Object
36 37 38 |
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb', line 36 def input_html_classes [] end |