Sha256: bc04197307759c61a359748447c2d3e7c00c390a1d95cc0e684f3dcf2ec47189

Contents?: true

Size: 730 Bytes

Versions: 4

Compression:

Stored size: 730 Bytes

Contents

module Formulaic
  module Inputs
    class CheckboxInput < ArrayInput
      def fill
        if has_check_boxes?
          check_boxes
          true
        else
          false
        end
      end

      private

      def has_check_boxes?
        contains_all_options?(checkbox_labels)
      end

      def check_boxes
        value.each { |checkbox| check checkbox }
      end

      def checkbox_labels
        all(checkbox_labels_selector)
      end

      def checkbox_name_selector
        "input[type='checkbox'][name='#{label.model_name}[#{label.attribute}][]']"
      end

      def checkbox_labels_selector
        "#{checkbox_name_selector} ~ label,label:has(#{checkbox_name_selector})"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formulaic-0.2.0 lib/formulaic/inputs/checkbox_input.rb
formulaic-0.1.4 lib/formulaic/inputs/checkbox_input.rb
formulaic-0.1.3 lib/formulaic/inputs/checkbox_input.rb
formulaic-0.1.2 lib/formulaic/inputs/checkbox_input.rb