Sha256: 917c52b54d17414788c590454fe1a60de2e1eaf1d3b7ca57a9679c20f3bec057

Contents?: true

Size: 1015 Bytes

Versions: 1

Compression:

Stored size: 1015 Bytes

Contents

module ActiveAdmin
  module Inputs
    class FilterBooleanInput < ::Formtastic::Inputs::BooleanInput
      include FilterBase

      def to_html
        input_wrapping do 
          [ label_html,
            check_box_html
          ].join("\n").html_safe
        end
      end

      def check_box_html
        template.check_box_tag("#{object_name}[#{method}]", checked_value, checked?, input_html_options)
      end

      def search_method
        method.to_s.match(metasearch_conditions) ? method : "#{method}_eq"
      end

      def checked?
        if defined? ActionView::Helpers::InstanceTag
          object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(search_method), checked_value)
        else
          object && boolean_checked?(object.send(search_method), checked_value)
        end
      end

      def input_html_options
        { :name => "q[#{search_method}]" }
      end

      def metasearch_conditions
        /is_true|is_false|is_present/
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin-0.5.1 lib/active_admin/inputs/filter_boolean_input.rb