Module: Maglev::Form::Inputs::Select

Included in:
FormBuilder
Defined in:
app/lib/maglev/form/inputs/select.rb

Instance Method Summary collapse

Instance Method Details

#select(method, select_options, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/lib/maglev/form/inputs/select.rb', line 7

def select(method, select_options, options = {})
  attributes = field_attributes(method)

  @template.render(Maglev::Uikit::Form::SelectComponent.new(
                     label: options[:label].presence || attributes[:content],
                     name: attributes[:name],
                     choices: select_options,
                     options: select_component_options(method, options),
                     html_options: select_component_html_options(options)
                   ))
end

#select_component_html_options(options) ⇒ Object



28
29
30
# File 'app/lib/maglev/form/inputs/select.rb', line 28

def select_component_html_options(options)
  options[:html_options] || {}
end

#select_component_options(method, options) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/lib/maglev/form/inputs/select.rb', line 19

def select_component_options(method, options)
  {
    value: options.key?(:value) ? options[:value] : object.public_send(method),
    prompt: options[:prompt],
    include_blank: options[:include_blank],
    error: error_messages(method)
  }
end