Sha256: 7b4e0c55d7a4f8432a8003b5eea052b9ba02ba70c20e4624225316887ef56750

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module FilterInputs
  class StringInput < SimpleForm::Inputs::StringInput
    def input(wrapper_options = nil)
      @wrapper_options = wrapper_options
      out = []
      out << select_html
      out << input_html
      out.join.html_safe
    end

    def select_html
      template.select_tag '', template.options_for_select(filter_options, current_filter), class: 'select_filter form-control'
    end

    def input_html
      merged_input_options = merge_wrapper_options(input_html_options, @wrapper_options)
      @builder.text_field current_filter, merged_input_options.merge(class: 'form-control')
    end

    def current_filter
      @current_filter ||= begin
        attributes = filters.map { |f| "#{attribute_name}_#{f}" }
        attributes.detect { |m| object.public_send m } || attributes.first
      end
    end

    def label_html
    end

    def filter_options
      filters.map do |filter|
        [filter, "#{attribute_name}_#{filter}"]
      end
    end

    def filters
      %w(cont eq start end)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adminos-1.0.0.pre.rc.5 app/inputs/filter_inputs/string_input.rb
adminos-1.0.0.pre.rc.4 app/inputs/filter_inputs/string_input.rb
adminos-1.0.0.pre.rc.3 app/inputs/filter_inputs/string_input.rb