Sha256: d71486a5a529744194c98241cb51f1b84c4c1ca01678dc65ee58c4e75a8f909c

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 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, collection, options[:value_method], options[:label_method], options, tag_options)
      end

      def collection
        @collection ||= begin
          collection = options.delete(:collection)
          collection.respond_to?(:call) ? collection.call : collection.to_a
        end
      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

7 entries across 7 versions & 1 rubygems

Version Path
effective_form_inputs-0.7.2 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.7.1 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.7.0 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.6.4 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.6.3 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.6.2 app/models/inputs/effective_select/input.rb
effective_form_inputs-0.6.1 app/models/inputs/effective_select/input.rb