Class: BetweenOrEqualInput

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

Instance Method Summary collapse

Instance Method Details

#gteq_fieldObject



13
14
15
# File 'app/inputs/between_or_equal_input.rb', line 13

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

#gteq_input_html_optionsObject



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

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



17
18
19
20
# File 'app/inputs/between_or_equal_input.rb', line 17

def gteq_value
  return unless object
  object.send(:"#{attribute_name}_gteq".to_sym)
end

#input(wrapper_options) ⇒ Object



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

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



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

def label_target
  :"#{attribute_name}_gteq"
end

#literal_andObject



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

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

#lteq_fieldObject



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

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

#lteq_input_html_optionsObject



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

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



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

def lteq_value
  return unless object
  object.send(:"#{attribute_name}_lteq".to_sym)
end

#span_gteqObject



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

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

#span_lteqObject



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

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