Sha256: a370179673b83cfb889017eae4122c31addf27228047eb6a11497a922247acf2

Contents?: true

Size: 988 Bytes

Versions: 25

Compression:

Stored size: 988 Bytes

Contents

require 'action_view/helpers/tags/placeholderable'

module RedmineExtensions
  module Tags
    class AutocompleteField < ActionView::Helpers::Tags::Base
      include ActionView::Helpers::Tags::Placeholderable

      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

      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

    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
redmine_extensions-1.2.0 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-1.1.2 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-1.1.1 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-1.1.0 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-1.0.0 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.6.3 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.6.2 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.6.1 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.6.0 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.5 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.5.1 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.4 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.3 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.1 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.0 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.4.0.beta lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.3.11 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.3.10 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.3.9 lib/redmine_extensions/tags/autocomplete_field.rb
redmine_extensions-0.3.8 lib/redmine_extensions/tags/autocomplete_field.rb