Class: Bard::TagField::Field

Inherits:
ActionView::Helpers::Tags::TextField
  • Object
show all
Defined in:
lib/bard/tag_field/field.rb

Instance Method Summary collapse

Instance Method Details

#render(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bard/tag_field/field.rb', line 4

def render &block
  add_default_name_and_id(@options)

  # Remove choices from HTML options before rendering
  choices = @options.delete(:choices)

  # Store choices for render_object_values method
  @choices = choices

  result = @template_object.("input-tag", @options) do
    content = block ? block.call(@options) : render_object_values

    # Add nested anonymous datalist if we have choices, no block, and no external list specified
    if choices&.any? && !block && !@options[:list]
      content += render_datalist(nil, choices)
    end

    content
  end

  result
end