Class: StorePickerInput

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

Overview

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



15
16
17
18
19
# File 'app/inputs/store_picker_input.rb', line 15

def collection
  return [] unless selected_value

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

#input(wrapper_options = nil) ⇒ Object



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

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