Module: Maglev::Form::Inputs::TextField

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

Instance Method Summary collapse

Instance Method Details

#text_field(method, options = {}) ⇒ Object



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

def text_field(method, options = {})
  attributes = field_attributes(method)

  @template.render(Maglev::Uikit::Form::TextFieldComponent.new(
                     label: options[:label].presence || attributes[:content],
                     name: attributes[:name],
                     options: text_field_component_options(method, options),
                     html_options: text_field_component_html_options(options)
                   ))
end

#text_field_component_html_options(options) ⇒ Object



26
27
28
# File 'app/lib/maglev/form/inputs/text_field.rb', line 26

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

#text_field_component_options(method, options) ⇒ Object



18
19
20
21
22
23
24
# File 'app/lib/maglev/form/inputs/text_field.rb', line 18

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