Class: Formtastic::Inputs::SelectableCheckBoxesInput

Inherits:
CheckBoxesInput
  • Object
show all
Defined in:
lib/formtastic/inputs/selectable_check_boxes.rb

Instance Method Summary collapse

Instance Method Details

#select_all_htmlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/formtastic/inputs/selectable_check_boxes.rb', line 21

def select_all_html
  choice_wrapping({}) do
    check_box = template.check_box_tag(nil, nil, false, 
      :onclick => <<-JS
        selector  = $(this);
        condition = selector.is(':checked');

        selector.closest('.choices-group').find('[type=checkbox]').attr('checked', condition);
      JS
    )

    template.(:label,
      check_box << I18n.t('select_all')
    )
  end
end

#to_htmlObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/formtastic/inputs/selectable_check_boxes.rb', line 4

def to_html
  input_wrapping do
    choices_wrapping do
      legend_html <<
      hidden_field_for_all <<
      choices_group_wrapping do
        select_all_html +
        collection.map { |choice|
          choice_wrapping(choice_wrapping_html_options(choice)) do
            choice_html(choice)
          end
        }.join("\n").html_safe
      end
    end
  end
end