Class: FoundationSwitchInput

Inherits:
SimpleForm::Inputs::CollectionRadioButtonsInput
  • Object
show all
Defined in:
app/inputs/foundation_switch_input.rb

Instance Method Summary collapse

Instance Method Details

#inputObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/inputs/foundation_switch_input.rb', line 2

def input
  options = input_options

  # do not wrap items in tags
  options[:item_wrapper_tag] = false

  # setting custom labels if provided
  if options[:labels]
    collection = [false, true].zip(options[:labels])
  else
    collection = [[false, 'No'], [true, 'Yes']]
  end

  # internal helpers to worki with collection
  label_method = :last
  value_method = :first

  html = @builder.send("collection_radio_buttons",
    attribute_name, collection, value_method, label_method,
    options, input_html_options, &collection_block_for_nested_boolean_style
  )

  # wrap html into foundation layout

  "<div class='switch round'>#{ html }<span></span></div>"
end