Class: StorePickerTomSelectInput

Inherits:
TomSelectInput
  • Object
show all
Defined in:
app/inputs/store_picker_tom_select_input.rb

Overview

Tom Select version of StorePickerInput
Use as: :store_picker_tom_select instead of :store_picker
Supports remote search via /stores/lookup endpoint
Pass company_id via query_params to filter by company

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input_html_classes

Instance Method Details

#collectionObject



16
17
18
19
20
# File 'app/inputs/store_picker_tom_select_input.rb', line 16

def collection
  return [] unless selected_value

  Store.where(id: selected_value).map { |s| [s.name, s.id] }
end

#input(wrapper_options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'app/inputs/store_picker_tom_select_input.rb', line 6

def input(wrapper_options = nil)
  input_html_options[:data] ||= {}
  query_params = options[:query_params] || input_html_options[:query_params] || {}
  input_html_options[:data]['tom-select-suggest-url-value'] = template.lookup_stores_path(query_params)
  input_html_options[:data]['tom-select-min-chars-value'] = 0
  input_html_options[:data]['tom-select-preload-value'] = true

  super
end