Class: SourcePickerInput

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

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input_html_classes

Instance Method Details

#collectionObject



15
16
17
# File 'app/inputs/source_picker_input.rb', line 15

def collection
  Source.where(id: selected_value).map { |e| [e.name_for_select, e.id] }
end

#input(wrapper_options = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/inputs/source_picker_input.rb', line 2

def input(wrapper_options = nil)
  params = {}
  params[:unrestricted] = true if input_html_options.dig(:data, :unrestricted).to_b
  params[:source_id_not_in] = input_html_options.dig(:data, :source_id_not_in)
  url = Web::UrlBuilder.new.process("/sources/lookup", nil, parameters: params)
  input_html_options[:multiple] = false if input_html_options[:multiple].nil?
  input_html_options[:data] ||= {}
  input_html_options[:data]['tom-select-suggest-url-value'] = url
  input_html_options[:data]['tom-select-min-chars-value'] = 0
  input_html_options[:data]['tom-select-preload-value'] = true
  super(wrapper_options)
end