Class: Conjoin::FormBuilder::RadioInput

Inherits:
Input
  • Object
show all
Defined in:
lib/conjoin/inputs/radio.rb

Direct Known Subclasses

BooleanInput

Instance Attribute Summary

Attributes inherited from Input

#app, #data, #options, #record

Instance Method Summary collapse

Methods inherited from Input

#errors?, #id, #initialize, #nested_name, #render

Constructor Details

This class inherits a constructor from Conjoin::FormBuilder::Input

Instance Method Details

#displayObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/conjoin/inputs/radio.rb', line 4

def display
  options[:type] = :radio
  options[:class].gsub!(/form-control/, '')

  radios = options[:radios] || [:yes, :no]

  opts = options.dup

  mab do
    div class: 'form-control' do
      radios.each_with_index do |name, i|
        name = name.to_s
        opts[:value] = name
        opts[:id]    =  "#{options[:id]}_#{i}"

        if (opts[:value] == 'no' and data.value == false) \
        or (opts[:value] == 'yes' and data.value == true) \
        or (opts[:value] == data.value)
          opts[:checked] = 'checked'
        else
          opts.delete :checked
        end

        input opts
        span name.humanize
      end
    end
  end
end