Class: RadioWithClearInput

Inherits:
SimpleForm::Inputs::CollectionInput
  • Object
show all
Defined in:
app/inputs/radio_with_clear_input.rb

Instance Method Summary collapse

Instance Method Details

#inputObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/inputs/radio_with_clear_input.rb', line 10

def input
  input_options[:collection_wrapper_tag] ||= options.fetch(:collection_wrapper_tag, SimpleForm.collection_wrapper_tag)
  input_options[:item_wrapper_class] ||= 'uc-form-collection-item'
  # Create a duplicate hidden field with a value of nil on top of existing
  # radio buttons so a user can clear their selection.
  # Selected radio buttons override this value.
  hidden_field = @builder.hidden_field(
    attribute_name,
    input_html_options.merge(:value => nil).merge(
      class: input_html_classes.join(' ')
    )
  )
  label_method, value_method = detect_collection_methods
  input_dom = @builder.send(:"collection_#{input_type}_buttons",
                            attribute_name, collection,
                            value_method, label_method,
                            input_options, input_html_options)
  dom = "  <fieldset class='radio_buttons normal row uc-form-fieldset-radio-with-clear'>\n    <div class=\"three fifths small-tablet pad-right\">\n      <legend class=\"uc-form-legend\">\#{input_options[:label]}</legend>\n    </div>\n    <div class='options two fifths small-tablet align-right' data-presents='radio_with_clear'>\n      \#{hidden_field}\n        \#{input_dom}\n      <a href='#'>clear</a>\n    </div>\n  </fieldset>\n  STRING\n  dom.html_safe\nend\n"

#input_typeObject



6
7
8
# File 'app/inputs/radio_with_clear_input.rb', line 6

def input_type
  "radio"
end

#labelObject



2
3
4
# File 'app/inputs/radio_with_clear_input.rb', line 2

def label
  ""
end