Class: RedmineExtensions::Tags::AutocompleteField

Inherits:
ActionView::Helpers::Tags::Base
  • Object
show all
Includes:
ActionView::Helpers::Tags::Placeholderable
Defined in:
lib/redmine_extensions/tags/autocomplete_field.rb

Instance Method Summary collapse

Constructor Details

#initialize(object_name, method_name, template_object, choices, options, html_options) ⇒ AutocompleteField

Returns a new instance of AutocompleteField.



8
9
10
11
12
13
14
15
16
17
# File 'lib/redmine_extensions/tags/autocomplete_field.rb', line 8

def initialize(object_name, method_name, template_object, choices, options, html_options)
  @choices = block_given? ? template_object.capture { yield || "" } : choices
  @choices = @choices.to_a if @choices.is_a?(Range)

  options[:multiple] = true unless options.key?(:multiple)

  @html_options = html_options

  super(object_name, method_name, template_object, html_options.merge(options))
end

Instance Method Details

#renderObject



19
20
21
22
23
24
# File 'lib/redmine_extensions/tags/autocomplete_field.rb', line 19

def render
  options = @options.stringify_keys
  options["value"] = options.fetch("value") { value_before_type_cast }
  add_default_name_and_id(options)
  @template_object.autocomplete_field_tag(options.delete('name'), @choices, options.delete('value'), options.symbolize_keys)
end