Class: Effective::FormInputs::Select

Inherits:
CollectionInput show all
Defined in:
app/models/effective/form_inputs/select.rb

Constant Summary

Constants inherited from Effective::FormInput

Effective::FormInput::BLANK, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES

Instance Attribute Summary

Attributes inherited from Effective::FormInput

#name, #options

Instance Method Summary collapse

Methods inherited from CollectionInput

#assign_options_collection!, #assign_options_collection_methods!, #collection_options, #custom?, #group_label_method, #group_method, #grouped?, #html_options, #initialize, #inline?, #label_method, #option_key_method, #option_value_method, #options_collection, #polymorphic?, #polymorphic_id_method, #polymorphic_id_value, #polymorphic_type_method, #polymorphic_type_value, #polymorphic_value, #value_method

Methods inherited from Effective::FormInput

#feedback_options, #hint_options, #initialize, #input_group_options, #label_options, #to_html, #wrapper_options

Constructor Details

This class inherits a constructor from Effective::FormInputs::CollectionInput

Instance Method Details

#build_input(&block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/effective/form_inputs/select.rb', line 9

def build_input(&block)
  html = if grouped? && polymorphic?
    @builder.grouped_collection_select(polymorphic_id_method, options_collection, group_method, group_label_method, option_key_method, option_value_method, collection_options, html_options)
  elsif grouped?
    @builder.grouped_collection_select(name, options_collection, group_method, group_label_method, option_key_method, option_value_method, collection_options, html_options)
  else
    @builder.collection_select(name, options_collection, value_method, label_method, collection_options, html_options)
  end

  if polymorphic?
    html += @builder.hidden_field(polymorphic_type_method, value: polymorphic_type_value)
    html += @builder.hidden_field(polymorphic_id_method, value: polymorphic_id_value)
  end

  if single_selected?
    html.gsub!('selected="selected"', '') if html.sub!('selected="selected"', "selected='selected'")
  end

  html.html_safe
end

#input_html_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/effective/form_inputs/select.rb', line 45

def input_html_options
  classes = [
    'effective_select',
    'form-control',
    ('polymorphic' if polymorphic?),
    ('grouped' if grouped?),
    ('hide-disabled' if hide_disabled?),
    ('tags-input' if tags?),
  ].compact.join(' ')

  { class: classes, multiple: (true if multiple?), include_blank: !multiple? }.compact
end

#input_js_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/effective/form_inputs/select.rb', line 30

def input_js_options
  opts = {
    theme: 'bootstrap',
    minimumResultsForSearch: 6,
    width: 'style',
    placeholder: (input_html_options.delete(:placeholder) || 'Please choose'),
    allowClear: !multiple?,
    tokenSeparators: ([',', ';', '\n', '\t'] if tags?),
    tags: (true if tags?),
    template: js_template,
    containerClass: ('hide-disabled' if hide_disabled?),
    dropdownClass: ('hide-disabled' if hide_disabled?),
  }.compact
end