Class: Arara::Tags::CountrySelect
- Inherits:
-
ActionView::Helpers::Tags::Base
- Object
- ActionView::Helpers::Tags::Base
- Arara::Tags::CountrySelect
- Includes:
- CountrySelect::TagHelper
- Defined in:
- app/components/arara/tags/country_select.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(object_name, method_name, template_object, options, html_options) ⇒ CountrySelect
constructor
super(object_name, method_name, template_object, options) end.
-
#options_for_select(container, selected = nil) ⇒ Object
my method.
-
#render ⇒ Object
select_content_tag(option_tags, @options, @html_options) end.
- #select_content_tag(option_tags, options, html_options) ⇒ Object
Constructor Details
#initialize(object_name, method_name, template_object, options, html_options) ⇒ CountrySelect
super(object_name, method_name, template_object, options) end
16 17 18 19 20 |
# File 'app/components/arara/tags/country_select.rb', line 16 def initialize(object_name, method_name, template_object, , ) @html_options = super(object_name, method_name, template_object, ) end |
Instance Method Details
#options_for_select(container, selected = nil) ⇒ Object
my method
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/components/arara/tags/country_select.rb', line 53 def (container, selected = nil) return container if String === container selected, disabled = extract_selected_and_disabled(selected).map do |r| Array(r).map(&:to_s) end container.map do |element| html_attributes = option_html_attributes(element) text, value = option_text_and_value(element).map(&:to_s) html_attributes[:selected] ||= option_value_selected?(value, selected) html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled) html_attributes[:value] = value # also set the label html_attributes[:label] = text # and render our component @template_object.template.render(Arara::SelectItemComponent, html_attributes.symbolize_keys) end.join("\n").html_safe end |
#render ⇒ Object
select_content_tag(option_tags, @options, @html_options) end
48 49 50 |
# File 'app/components/arara/tags/country_select.rb', line 48 def render select_content_tag(, @options, @html_options) end |
#select_content_tag(option_tags, options, html_options) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/components/arara/tags/country_select.rb', line 76 def select_content_tag(, , ) = .stringify_keys 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: "") + select else select end = .merge() @template_object.template.render(Arara::SelectComponent, .symbolize_keys) do end end |