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 (, , value = nil) if [:include_blank] content = ( [:include_blank] if [:include_blank].is_a?(String)) label = (" " unless content) = tag_builder.content_tag_string("option", content, value: "", label: label) + "\n" + end if value.blank? && [:prompt] = { value: "" }.tap do |prompt_opts| prompt_opts[:disabled] = true if [:disabled] == "" prompt_opts[:selected] = true if [:selected] == "" end = tag_builder.content_tag_string("option", prompt_text( [:prompt]), ) + "\n" + end end
#placeholder_required?(html_options) ⇒ Boolean
(private)
# File 'actionview/lib/action_view/helpers/tags/select_renderer.rb', line 31
def placeholder_required?( ) # See https://html.spec.whatwg.org/multipage/forms.html#attr-select-required ["required"] && ! ["multiple"] && .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 select_content_tag(, , ) = .stringify_keys [:required, :multiple, :size].each do |prop| [prop.to_s] = .delete(prop) if .key?(prop) && ! .key?(prop.to_s) end add_default_name_and_id( ) if placeholder_required?( ) raise ArgumentError, "include_blank cannot be false for a required field." if [:include_blank] == false [:include_blank] ||= true unless [:prompt] end value = .fetch(:selected) { value() } select = content_tag("select", (, , value), ) if ["multiple"] && .fetch(:include_hidden, true) tag("input", disabled: ["disabled"], name: ["name"], type: "hidden", value: "", autocomplete: "off") + select else select end end