Class: Protoform::Rails::Components::Select
- Inherits:
-
FieldComponent
- Object
- Component
- FieldComponent
- Protoform::Rails::Components::Select
- Defined in:
- lib/protoform/rails/components/select.rb
Instance Method Summary collapse
- #blank_option(&block) ⇒ Object
- #false_option(&block) ⇒ Object
- #options(*collection) ⇒ Object
- #true_option(&block) ⇒ Object
- #view_template(&options) ⇒ Object
Methods inherited from Component
Instance Method Details
#blank_option(&block) ⇒ Object
38 39 40 |
# File 'lib/protoform/rails/components/select.rb', line 38 def blank_option(&block) option(selected: field.value.nil?, &block) end |
#false_option(&block) ⇒ Object
46 47 48 |
# File 'lib/protoform/rails/components/select.rb', line 46 def false_option(&block) option(selected: field.value == false, value: false.to_s, &block) end |
#options(*collection) ⇒ Object
32 33 34 35 36 |
# File 'lib/protoform/rails/components/select.rb', line 32 def (*collection) (collection).each do |key, value| option(selected: selected_value_for(key), value: key) { value } end end |
#true_option(&block) ⇒ Object
42 43 44 |
# File 'lib/protoform/rails/components/select.rb', line 42 def true_option(&block) option(selected: field.value == true, value: true.to_s, &block) end |
#view_template(&options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/protoform/rails/components/select.rb', line 11 def view_template(&) name = @multiple ? "#{attrs[:name]}[]" : attrs[:name] if @multiple input( name:, type: :hidden, value: "" ) end if select(multiple: @multiple, **attrs, name:, &) else select(multiple: @multiple, **attrs, name:) do blank_option if @include_blank (*@collection) end end end |