Sha256: 430e67bb583d9eb57b2436c6617086d383434d5783b30550c3712ea293aa0d57

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Inputs
  module EffectiveSelect
    class Input < Effective::FormInput
      delegate :collection_select, :to => :@template

      def default_options
        {:label_method => :to_s, :value_method => :to_s}
      end

      def default_input_js
        {theme: 'bootstrap', minimumResultsForSearch: 6, tokenSeparators: [',', ' '], width: 'style', placeholder: 'Please choose'}
      end

      def default_input_html
        {class: 'effective_select', placeholder: 'Please choose'}
      end

      def to_html
        collection_select(@object_name, @method, options[:collection], options[:label_method], options[:value_method], options, tag_options)
      end

      def options
        super().tap do |options|
          options[:selected] = value if value

          options[:multiple] = true if (options[:tags] == true)
          options[:include_blank] = (options[:multiple] != true)
        end
      end

      def html_options
        super().tap do |html_options|
          html_options[:multiple] = options[:multiple]
        end
      end

      def js_options
        super().tap do |js_options|
          js_options[:allowClear] = (options[:multiple] != true)
          js_options[:tags] = (options[:tags] == true)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
effective_form_inputs-0.6.0 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.5.0 app/models/inputs/effective_select/input.rb