Sha256: ad8ed546693f458b0869eedc6eb33b141cf8f0446d732dad50c082e87d2a1887

Contents?: true

Size: 1.46 KB

Versions: 19

Compression:

Stored size: 1.46 KB

Contents

class TagsInput < ActiveAdminAddons::InputBase
  include ActiveAdminAddons::SelectHelpers

  def render_custom_input
    if active_record_select?
      return render_collection_tags
    end

    render_array_tags
  end

  def load_control_attributes
    load_data_attr(:model, value: model_name)
    load_data_attr(:method, value: method)
    load_data_attr(:width, default: "80%")

    if active_record_select?
      load_data_attr(:relation, value: true)
      load_data_attr(:collection, value: collection_to_select_options, formatter: :to_json)
    else
      load_data_attr(:collection, value: array_to_select_options, formatter: :to_json)
    end
  end

  private

  def render_array_tags
    render_tags_control { build_hidden_control(prefixed_method, method_to_input_name, input_value) }
  end

  def render_collection_tags
    render_tags_control { render_selected_hidden_items }
  end

  def render_tags_control(&block)
    concat(label_html)
    concat(block.call)
    concat(builder.select(build_virtual_attr, [], {}, input_html_options))
  end

  def render_selected_hidden_items
    template.content_tag(:div, id: selected_values_id) do
      template.concat(build_hidden_control(empty_input_id, method_to_input_array_name, ""))
      input_value.each do |item_id|
        template.concat(
          build_hidden_control(
            method_to_input_id(item_id),
            method_to_input_array_name,
            item_id.to_s
          )
        )
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
activeadmin_addons-1.10.2 app/inputs/tags_input.rb
activeadmin_addons-1.10.1 app/inputs/tags_input.rb
activeadmin_addons-1.10.0 app/inputs/tags_input.rb
activeadmin_addons-1.9.0 app/inputs/tags_input.rb
activeadmin_addons-1.8.3 app/inputs/tags_input.rb
activeadmin_addons-1.8.2 app/inputs/tags_input.rb
activeadmin_addons_rails6-1.7.2 app/inputs/tags_input.rb
activeadmin_addons-1.7.1 app/inputs/tags_input.rb
activeadmin_addons-1.7.0 app/inputs/tags_input.rb
activeadmin_addons-1.6.0 app/inputs/tags_input.rb
activeadmin_addons-1.5.0 app/inputs/tags_input.rb
activeadmin_addons-1.4.0 app/inputs/tags_input.rb
activeadmin_addons-1.3.0 app/inputs/tags_input.rb
activeadmin_addons-1.2.0 app/inputs/tags_input.rb
activeadmin_addons-1.1.2 app/inputs/tags_input.rb
activeadmin_addons-1.1.1 app/inputs/tags_input.rb
activeadmin_addons-1.1.0 app/inputs/tags_input.rb
activeadmin_addons-1.0.1 app/inputs/tags_input.rb
activeadmin_addons-1.0.0 app/inputs/tags_input.rb