Class: BetweenOrEqualInput

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

Overview

SimpleForm input wrapper: between or equal.

Instance Method Summary collapse

Instance Method Details

#gteq_fieldObject



15
16
17
# File 'app/inputs/between_or_equal_input.rb', line 15

def gteq_field
  @builder.input_field(:"#{attribute_name}_gteq", gteq_input_html_options)
end

#gteq_input_html_optionsObject



31
32
33
# File 'app/inputs/between_or_equal_input.rb', line 31

def gteq_input_html_options
  input_html_options.merge({ as: :integer, placeholder: 'Greater than or equal to', value: gteq_value, class: 'form-control gteq_field' })
end

#gteq_valueObject



19
20
21
22
23
# File 'app/inputs/between_or_equal_input.rb', line 19

def gteq_value
  return unless object

  object.send(:"#{attribute_name}_gteq")
end

#input(_wrapper_options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'app/inputs/between_or_equal_input.rb', line 4

def input(_wrapper_options)
  # Be aware for I18n: translate the "and" here
  template.(:div, class: 'input-group') do
    template.concat span_gteq
    template.concat gteq_field
    template.concat literal_and
    template.concat lteq_field
    template.concat span_lteq
  end
end

#label_targetObject

Make the label be for the first of the two fields



56
57
58
# File 'app/inputs/between_or_equal_input.rb', line 56

def label_target
  :"#{attribute_name}_gteq"
end

#literal_andObject



47
48
49
# File 'app/inputs/between_or_equal_input.rb', line 47

def literal_and
  template.(:span, ' and ', class: 'input-group-text rounded-0')
end

#lteq_fieldObject



35
36
37
# File 'app/inputs/between_or_equal_input.rb', line 35

def lteq_field
  @builder.input_field(:"#{attribute_name}_lteq", lteq_input_html_options)
end

#lteq_input_html_optionsObject



39
40
41
# File 'app/inputs/between_or_equal_input.rb', line 39

def lteq_input_html_options
  input_html_options.merge({ as: :integer, placeholder: 'Less than or equal to', value: lteq_value, class: 'form-control lteq_field' })
end

#lteq_valueObject



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

def lteq_value
  return unless object

  object.send(:"#{attribute_name}_lteq")
end

#span_gteqObject



43
44
45
# File 'app/inputs/between_or_equal_input.rb', line 43

def span_gteq
  template.(:span, '>=', class: 'input-group-text')
end

#span_lteqObject



51
52
53
# File 'app/inputs/between_or_equal_input.rb', line 51

def span_lteq
  template.(:span, '<=', class: 'input-group-text')
end