Sha256: 3ca76a061438e61e9e88fe6757954e96d7720632b24e4958e459040e0921acb5

Contents?: true

Size: 1.57 KB

Versions: 35

Compression:

Stored size: 1.57 KB

Contents

class MultiValueSelectInput < MultiValueInput
  # Overriding so that the class is correct and the javascript for will work on this.
  # See https://github.com/samvera/hydra-editor/blob/4da9c0ea542f7fde512a306ec3cc90380691138b/app/assets/javascripts/hydra-editor/field_manager.es6#L61
  def input_type
    'multi_value'.freeze
  end

  private

    def select_options
      @select_options ||= begin
        collection = options.delete(:collection) || self.class.boolean_collection
        collection.respond_to?(:call) ? collection.call : collection.to_a
      end
    end

    def build_field_options(value)
      field_options = input_html_options.dup

      field_options[:value] = value
      if @rendered_first_element
        field_options[:id] = nil
        field_options[:required] = nil
      else
        field_options[:id] ||= input_dom_id
      end
      field_options[:class] ||= []
      field_options[:class] += ["#{input_dom_id} form-control multi-text-field"]
      field_options[:'aria-labelledby'] = label_id
      field_options.delete(:multiple)
      field_options.delete(:item_helper)
      field_options.merge!(options.slice(:include_blank))

      @rendered_first_element = true

      field_options
    end

    def build_field(value, index)
      render_options = select_options
      html_options = build_field_options(value)
      (render_options, html_options) = options[:item_helper].call(value, index, render_options, html_options) if options[:item_helper]
      template.select_tag(attribute_name, template.options_for_select(render_options, value), html_options)
    end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/inputs/multi_value_select_input.rb
hyrax-2.9.5 app/inputs/multi_value_select_input.rb
hyrax-2.9.4 app/inputs/multi_value_select_input.rb
hyrax-2.9.3 app/inputs/multi_value_select_input.rb
hyrax-2.9.2 app/inputs/multi_value_select_input.rb
hyrax-2.9.1 app/inputs/multi_value_select_input.rb
hyrax-2.9.0 app/inputs/multi_value_select_input.rb
hyrax-2.8.0 app/inputs/multi_value_select_input.rb
hyrax-2.7.2 app/inputs/multi_value_select_input.rb
hyrax-2.7.1 app/inputs/multi_value_select_input.rb
hyrax-2.7.0 app/inputs/multi_value_select_input.rb
hyrax-2.6.0 app/inputs/multi_value_select_input.rb
hyrax-3.0.0.pre.rc1 app/inputs/multi_value_select_input.rb
hyrax-3.0.0.pre.beta3 app/inputs/multi_value_select_input.rb
hyrax-2.5.1 app/inputs/multi_value_select_input.rb
hyrax-2.5.0 app/inputs/multi_value_select_input.rb
hyrax-3.0.0.pre.beta2 app/inputs/multi_value_select_input.rb
hyrax-2.4.1 app/inputs/multi_value_select_input.rb
hyrax-3.0.0.pre.beta1 app/inputs/multi_value_select_input.rb
hyrax-2.4.0 app/inputs/multi_value_select_input.rb