Class: Inputs::EffectiveSelect::Input

Inherits:
Effective::FormInput show all
Defined in:
app/models/inputs/effective_select/input.rb

Instance Method Summary collapse

Methods inherited from Effective::FormInput

#field_name, #initialize, #value

Constructor Details

This class inherits a constructor from Effective::FormInput

Instance Method Details

#collectionObject



22
23
24
25
26
27
# File 'app/models/inputs/effective_select/input.rb', line 22

def collection
  @collection ||= begin
    collection = options.delete(:collection)
    collection.respond_to?(:call) ? collection.call : collection.to_a
  end
end

#default_input_htmlObject



14
15
16
# File 'app/models/inputs/effective_select/input.rb', line 14

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

#default_input_jsObject



10
11
12
# File 'app/models/inputs/effective_select/input.rb', line 10

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

#default_optionsObject



6
7
8
# File 'app/models/inputs/effective_select/input.rb', line 6

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

#html_optionsObject



38
39
40
41
42
# File 'app/models/inputs/effective_select/input.rb', line 38

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

#js_optionsObject



44
45
46
47
48
49
# File 'app/models/inputs/effective_select/input.rb', line 44

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

#optionsObject



29
30
31
32
33
34
35
36
# File 'app/models/inputs/effective_select/input.rb', line 29

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

#to_htmlObject



18
19
20
# File 'app/models/inputs/effective_select/input.rb', line 18

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