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 ⇒ Object
- #false_option ⇒ Object
- #options(*collection) ⇒ Object
- #true_option ⇒ Object
- #view_template(&options) ⇒ Object
Methods inherited from Component
Instance Method Details
#blank_option ⇒ Object
38 39 40 |
# File 'lib/protoform/rails/components/select.rb', line 38 def blank_option(&) option(selected: field.value.nil?, &) end |
#false_option ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/protoform/rails/components/select.rb', line 50 def false_option(&) option( selected: field.value == false, value: false.to_s, & ) 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.to_s) { value } end end |
#true_option ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/protoform/rails/components/select.rb', line 42 def true_option(&) option( selected: field.value == true, value: true.to_s, & ) 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 |