Class: IRuby::Input::Radio

Inherits:
Label
  • Object
show all
Defined in:
lib/iruby/input/radio.rb

Instance Method Summary collapse

Methods inherited from Label

#widget_label

Methods inherited from Widget

builder, #content, #widget_display, #widget_join

Instance Method Details

#widget_cssObject



16
17
18
19
20
21
# File 'lib/iruby/input/radio.rb', line 16

def widget_css
  <<-CSS
    .iruby-radio.form-control { display: inline-table; }
    .iruby-radio .radio-inline { margin: 0 15px 0 0; }
  CSS
end

#widget_htmlObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/iruby/input/radio.rb', line 35

def widget_html
  params = {
    :'data-iruby-key' => @key,
    :'data-iruby-value' => @options.first,
    class: 'iruby-radio form-control'
  }
  widget_label do
    div **params do
      @options.each do |option|
        label class: 'radio-inline' do
          input(
            name: @key,
            value: option,
            type: 'radio',
            checked: @default == option
          )
          text option
        end
      end
    end
  end
end

#widget_jsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/iruby/input/radio.rb', line 23

def widget_js
  <<-JS
    $('.iruby-radio input').change(function(){
      var parent = $(this).closest('.iruby-radio');
      $(parent).data('iruby-value',
        $(parent).find(':checked').val()
      );
    });
    $('.iruby-radio input').trigger('change');
  JS
end