class IRuby::Input::Checkbox

Public Instance Methods

widget_css() click to toggle source
# File lib/iruby/input/checkbox.rb, line 25
      def widget_css
        <<-CSS
          .iruby-checkbox.form-control { display: inline-table; }
          .iruby-checkbox .checkbox-inline { margin: 0 15px 0 0; }
        CSS
      end
widget_html() click to toggle source
# File lib/iruby/input/checkbox.rb, line 51
def widget_html
  params = {
    :'data-iruby-key' => @key,
    class: 'iruby-checkbox form-control'
  }
  widget_label do
    div **params do
      @options.each do |option|
        label class: 'checkbox-inline' do 
          input(
            name: @key, 
            value: option, 
            type: 'checkbox',
            checked: @default.include?(option)
          )
          text option
        end
      end
    end
  end
end
widget_js() click to toggle source
# File lib/iruby/input/checkbox.rb, line 32
      def widget_js
        <<-JS
          $('.iruby-checkbox input').change(function(){
            var parent = $(this).closest('.iruby-checkbox');
            $(parent).data('iruby-value', []);

            $(parent).find(':checked').each(function(){
              $(parent).data('iruby-value').push($(this).val());
            });

            if ($(parent).data('iruby-value').length == 0) {
              $(parent).data('iruby-value', null);
            }
          });

          $('.iruby-checkbox input').trigger('change');
        JS
      end