123456789_123456789_123456789_123456789_123456789_

Module: ActionView::Helpers::Tags::SelectRenderer

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: actionview/lib/action_view/helpers/tags/select_renderer.rb

Instance Method Summary

Instance Method Details

#add_options(option_tags, options, value = nil) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/tags/select_renderer.rb', line 36

def add_options(option_tags, options, value = nil)
  if options[:include_blank]
    content = (options[:include_blank] if options[:include_blank].is_a?(String))
    label = (" " unless content)
    option_tags = tag_builder.("option", content, value: "", label: label) + "\n" + option_tags
  end

  if value.blank? && options[:prompt]
    tag_options = { value: "" }.tap do |prompt_opts|
      prompt_opts[:disabled] = true if options[:disabled] == ""
      prompt_opts[:selected] = true if options[:selected] == ""
    end
    option_tags = tag_builder.("option", prompt_text(options[:prompt]), tag_options) + "\n" + option_tags
  end

  option_tags
end

#placeholder_required?(html_options) ⇒ Boolean (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/tags/select_renderer.rb', line 31

def placeholder_required?(html_options)
  # See https://html.spec.whatwg.org/multipage/forms.html#attr-select-required
  html_options["required"] && !html_options["multiple"] && html_options.fetch("size", 1).to_i == 1
end

#select_content_tag(option_tags, options, html_options) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/tags/select_renderer.rb', line 8

def (option_tags, options, html_options)
  html_options = html_options.stringify_keys
  [:required, :multiple, :size].each do |prop|
    html_options[prop.to_s] = options.delete(prop) if options.key?(prop) && !html_options.key?(prop.to_s)
  end

  add_default_name_and_id(html_options)

  if placeholder_required?(html_options)
    raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
    options[:include_blank] ||= true unless options[:prompt]
  end

  value = options.fetch(:selected) { value() }
  select = ("select", add_options(option_tags, options, value), html_options)

  if html_options["multiple"] && options.fetch(:include_hidden, true)
    tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "", autocomplete: "off") + select
  else
    select
  end
end