Sha256: f9ed18f670f3d9d616337740aaeb22d0fb51b3c04a8b5303bf5d4c037a14366e

Contents?: true

Size: 1.82 KB

Versions: 20

Compression:

Stored size: 1.82 KB

Contents

<%
stimulus_controller = 'fields--super-select'

form ||= current_fields_form
options ||= {}
other_options ||= {}
select2_options ||= nil
html_options ||= {}
html_options[:id] ||= form.field_id(method)
html_options[:class] = "form-control select2 #{html_options[:class]}".strip
choices_url ||= nil
if choices_url.nil?
  choices ||= options_for(form, method)&.invert
else
  # If we have a choices_url, we're going to lazy load the choices.  However, we still want to show the currently selected option.
  method_without_id = method.to_s.gsub("_id", "")
  if current_selection = form.object.send(method_without_id)
    choices = [[current_selection.label_string, current_selection.id]]
  else
    choices = {}
  end
end

wrapper_options = { data: { controller: stimulus_controller }}
wrapper_options[:data]["#{stimulus_controller}-enable-search-value"] = true if other_options[:search]
wrapper_options[:data]["#{stimulus_controller}-accepts-new-value"] = true if other_options[:accepts_new]
wrapper_options[:data]["#{stimulus_controller}-search-url-value"] = choices_url if choices_url.present?
wrapper_options[:data]["#{stimulus_controller}-select2-options-value"] = select2_options.to_json if select2_options.present?

unless options[:multiple]
  wrapper_options[:data]["action"] ||= ""
  wrapper_options[:data]["action"] += " keydown->#{stimulus_controller}#injectKeystrokeIntoTextField $select2:open->#{stimulus_controller}#focusOnTextField"
end

html_options[:data] ||= {}
html_options[:data].merge!("#{stimulus_controller}-target": 'select')

%>

<%= render 'shared/fields/field', form: form, method: method, options: html_options, other_options: other_options do %>
  <% content_for :field do %>
    <%= content_tag :div, data: wrapper_options[:data] do %>
      <%= form.select method, choices, options, html_options %>
    <% end %>
  <% end %>
<% end %>

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bullet_train-themes-1.3.19 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.18 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.17 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.16 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.15 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.14 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.13 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.12 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.11 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.10 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.9 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.8 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.7 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.6 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.5 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.4 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.3 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.2 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.1 app/views/themes/base/fields/_super_select.html.erb
bullet_train-themes-1.3.0 app/views/themes/base/fields/_super_select.html.erb