Class: Superform::Rails::Components::Datalist
- Inherits:
-
Field
- Object
- Base
- Field
- Superform::Rails::Components::Datalist
show all
- Defined in:
- lib/superform/rails/components/datalist.rb
Instance Attribute Summary
Attributes inherited from Base
#dom, #field
Instance Method Summary
collapse
Methods inherited from Field
#field_attributes
Methods inherited from Base
#field_attributes, #focus
Constructor Details
#initialize(field, options: [], **attributes) ⇒ Datalist
Returns a new instance of Datalist.
5
6
7
8
|
# File 'lib/superform/rails/components/datalist.rb', line 5
def initialize(field, options: [], **attributes)
super(field, **attributes)
@options = options
end
|
Instance Method Details
#options(*collection) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/superform/rails/components/datalist.rb', line 22
def options(*collection)
Choices::Mapper.new(collection).each do |value, text|
if value == text
option(value: value)
else
option(value: value) { text }
end
end
end
|
#view_template(&block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/superform/rails/components/datalist.rb', line 10
def view_template(&block)
datalist_id = DOM.join(dom.id, "datalist")
input(list: datalist_id, **attributes)
datalist(id: datalist_id) do
if block
yield self
else
options(*@options)
end
end
end
|