Class: Effective::FormInputs::Select
- Inherits:
-
CollectionInput
- Object
- Effective::FormInput
- CollectionInput
- Effective::FormInputs::Select
- Defined in:
- app/models/effective/form_inputs/select.rb
Direct Known Subclasses
Constant Summary collapse
- INCLUDE_NULL =
'Blank (null)'
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
Instance Method Summary collapse
- #assign_options_collection! ⇒ Object
- #build_input(&block) ⇒ Object
- #input_html_options ⇒ Object
- #input_js_options ⇒ Object
Methods inherited from CollectionInput
#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, #translate, #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
#assign_options_collection! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/effective/form_inputs/select.rb', line 62 def super return unless include_null # Check for singles - transform the array if .kind_of?(Array) && !.first.respond_to?(:to_a) # [:admin, :member] @options_collection = .map { |obj| [obj, obj] } end if .kind_of?(Array) && .first.respond_to?(:to_a) .push(['---------------', '-', disabled: 'disabled']) .push([include_null, 'nil']) end if .kind_of?(Hash) [include_null] = [[include_null, 'nil']] end end |
#build_input(&block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/effective/form_inputs/select.rb', line 10 def build_input(&block) html = if polymorphic? @builder.grouped_collection_select(polymorphic_id_method, , group_method, group_label_method, option_key_method, option_value_method, , ) elsif grouped? @builder.grouped_collection_select(name, , group_method, group_label_method, option_key_method, option_value_method, , ) else @builder.collection_select(name, , value_method, label_method, , ) 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_options ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/effective/form_inputs/select.rb', line 49 def classes = [ 'effective_select', 'form-control', ('polymorphic' if polymorphic?), ('grouped' if (grouped? || polymorphic?)), ('hide-disabled' if hide_disabled?), ('tags-input' if ), ].compact.join(' ') { class: classes, multiple: (true if multiple?), include_blank: (true if include_blank?), include_null: include_null }.compact end |
#input_js_options ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/effective/form_inputs/select.rb', line 31 def placeholder = .delete(:placeholder) placeholder = '' if placeholder == false opts = { theme: 'bootstrap', minimumResultsForSearch: 6, width: 'style', placeholder: (placeholder || 'Please choose'), allowClear: (true if include_blank?), tokenSeparators: ([',', ';', '\n', '\t'] if ), tags: (true if ), template: js_template, containerClass: ('hide-disabled' if hide_disabled?), dropdownClass: ('hide-disabled' if hide_disabled?), }.compact end |