Class: SymbolizedInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
app/inputs/symbolized_input.rb

Overview

SimpleForm input wrapper: symbolized.

Direct Known Subclasses

MoneyInput

Instance Method Summary collapse

Instance Method Details

#input(_wrapper_options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/inputs/symbolized_input.rb', line 4

def input(_wrapper_options)
  group_classes = ['input-group']
  extra_group_class = input_html_options[:input_group_class] || options[:input_group_class]
  group_classes << extra_group_class if extra_group_class
  template.(:div, class: group_classes.compact.join(' ')) do
    if input_html_options[:left_symbol] || input_html_options[:right_symbol]
      template.concat span_symbol(:left_symbol) if input_html_options[:left_symbol]
      template.concat render_field
      template.concat span_symbol(:right_symbol) if input_html_options[:right_symbol]
    elsif input_html_options[:position] == :right
      template.concat render_field
      template.concat span_symbol
    else
      template.concat span_symbol
      template.concat render_field
    end
  end
end

#input_html_classesObject



23
24
25
# File 'app/inputs/symbolized_input.rb', line 23

def input_html_classes
  (super || []).push('form-control').uniq
end

#render_fieldObject



32
33
34
# File 'app/inputs/symbolized_input.rb', line 32

def render_field
  @builder.input_field(attribute_name, input_html_options)
end

#span_symbol(option_key = :symbol) ⇒ Object



27
28
29
30
# File 'app/inputs/symbolized_input.rb', line 27

def span_symbol(option_key = :symbol)
  symbol = input_html_options[option_key] || options[option_key] || '?'
  template.(:span, symbol, class: 'input-group-text')
end