Sha256: 9b0cbd636692c91b175873ac729c19420c8a78b43df1727e5b31a54313009a88
Contents?: true
Size: 1.43 KB
Versions: 23
Compression:
Stored size: 1.43 KB
Contents
<% yield %> <% stimulus_controller = 'fields--super-select' form ||= current_fields_form options ||= {} other_options ||= {} html_options ||= {} html_options[:id] ||= id_for(form, 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? html_options[:data] = { "#{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
23 entries across 23 versions & 2 rubygems