Class: SymbolizedInput

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

Direct Known Subclasses

MoneyInput

Instance Method Summary collapse

Instance Method Details

#input(_wrapper_options) ⇒ Object



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

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



21
22
23
# File 'app/inputs/symbolized_input.rb', line 21

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

#render_fieldObject



30
31
32
# File 'app/inputs/symbolized_input.rb', line 30

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

#span_symbol(option_key = :symbol) ⇒ Object



25
26
27
28
# File 'app/inputs/symbolized_input.rb', line 25

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