File: collection_check_boxes.rb

package info (click to toggle)
ruby-bootstrap-form 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 512 kB
  • sloc: ruby: 1,350; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download
1
2
3
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
33
34
35
# frozen_string_literal: true

module BootstrapForm
  module Inputs
    module CollectionCheckBoxes
      extend ActiveSupport::Concern
      include Base
      include InputsCollection

      included do
        def collection_check_boxes_with_bootstrap(*args)
          html = inputs_collection(*args) do |name, value, options|
            options[:multiple] = true
            check_box(name, options, value, nil)
          end

          if args.extract_options!.symbolize_keys!.delete(:include_hidden) { true }
            html.prepend hidden_field(args.first, value: "", name: field_name(args[0], multiple: true))
          end
          html
        end

        bootstrap_alias :collection_check_boxes

        if Rails::VERSION::MAJOR < 7
          def field_name(method, *methods, multiple: false, index: @options[:index])
            object_name = @options.fetch(:as) { @object_name }

            @template.field_name(object_name, method, *methods, index: index, multiple: multiple)
          end
        end
      end
    end
  end
end