Class: Superform::Rails::Components::Select
- Inherits:
-
Field
- Object
- Base
- Field
- Superform::Rails::Components::Select
show all
- Defined in:
- lib/superform/rails/components/select.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(collection: []) ⇒ Select
Returns a new instance of Select.
5
6
7
8
|
# File 'lib/superform/rails/components/select.rb', line 5
def initialize(*, collection: [], **, &)
super(*, **, &)
@collection = collection
end
|
Instance Method Details
#blank_option ⇒ Object
24
25
26
|
# File 'lib/superform/rails/components/select.rb', line 24
def blank_option(&)
option(selected: field.value.nil?, &)
end
|
#false_option ⇒ Object
32
33
34
|
# File 'lib/superform/rails/components/select.rb', line 32
def false_option(&)
option(selected: field.value == false, value: false.to_s, &)
end
|
#options(*collection) ⇒ Object
18
19
20
21
22
|
# File 'lib/superform/rails/components/select.rb', line 18
def options(*collection)
map_options(collection).each do |key, value|
option(selected: field.value == key, value: key) { value }
end
end
|
#true_option ⇒ Object
28
29
30
|
# File 'lib/superform/rails/components/select.rb', line 28
def true_option(&)
option(selected: field.value == true, value: true.to_s, &)
end
|
#view_template(&options) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/superform/rails/components/select.rb', line 10
def view_template(&options)
if block_given?
select(**attributes, &options)
else
select(**attributes) { options(*@collection) }
end
end
|