Module: ActiveAdmin::SearchableSelect::SelectInputExtension

Included in:
Inputs::Filters::SearchableSelectInput, Inputs::SearchableSelectInput
Defined in:
lib/activeadmin/searchable_select/select_input_extension.rb

Overview

Mixin for searchable select inputs.

Supports the same options as inputs of type :select.

Adds support for an ajax option to fetch options data from a JSON endpoint. Pass either true to use defaults or a hash containing some of the following options:

  • resource: ActiveRecord model class of ActiveAdmin resource which provides the collection action to fetch options from. By default the resource is auto detected via the name of the input attribute.

  • collection_name: Name passed to the searchable_select_options method that defines the collection action to fetch options from.

  • params: Hash of query parameters that shall be passed to the options endpoint.

  • path_params: Hash of parameters, which would be passed to the dynamic collection path generation for the resource. e.g admin_articles_path(path_params)

If the ajax option is present, the collection option is ignored.

Instance Method Summary collapse

Instance Method Details

#collection_from_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
46
# File 'lib/activeadmin/searchable_select/select_input_extension.rb', line 38

def collection_from_options
  return super unless options[:ajax]

  if SearchableSelect.inline_ajax_options
    all_options_collection
  else
    selected_value_collection
  end
end

#input_html_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
# File 'lib/activeadmin/searchable_select/select_input_extension.rb', line 31

def input_html_options
  options = super
  options[:class] = [options[:class], 'searchable-select-input'].compact.join(' ')
  options.merge('data-ajax-url' => ajax_url)
end