Module: Decidim::DatalistSelectHelper
- Defined in:
- decidim-core/app/helpers/decidim/datalist_select_helper.rb
Overview
Helper that provides a single method to create datalist select.
Instance Method Summary collapse
-
#datalist_select(items, options = {}) ⇒ Object
Public: Creates HTML for datalist select so that you can use seperate ids and labels.
Instance Method Details
#datalist_select(items, options = {}) ⇒ Object
Public: Creates HTML for datalist select so that you can use seperate ids and labels.
items - Items in datalist, item should have id and name. options - a Hash with options
:id - id of wrapper
:class - wrapper css classes
:data - wrapper data attributes
:label - label for input
:name - name of input
:autocomplete - enable or disable autocomplete provided by browser.
:list - id of datalist
yield - additional html (e.g. hidden input)
Returns a HTML String div containing following children: label, input and datalist elements.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'decidim-core/app/helpers/decidim/datalist_select_helper.rb', line 20 def datalist_select(items, = {}) = { list: "datalist-list", autocomplete: "off" } = .merge() tag.div(id: [:id], class: [:class], data: [:data]) do html = "" html += yield if block_given? html += tag.label([:label], for: [:name]) html += tag.input(type: "text", name: [:name], list: [:list], autocomplete: [:autocomplete], placeholder: [:placeholder]) html += tag.datalist(id: [:list]) do items.map do |item| tag.option(translated_attribute(item.name), data: { value: item.id }) end.join.html_safe end html.html_safe end end |