Class: DatetimePickerInput

Inherits:
SimpleForm::Inputs::StringInput
  • Object
show all
Defined in:
app/inputs/datetime_picker_input.rb

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
20
21
22
23
24
25
26
27
# File 'app/inputs/datetime_picker_input.rb', line 2

def input(wrapper_options)
  floating = options.fetch(:floating, false)

  dt_val = object.try(attribute_name).try(:strftime, '%Y-%m-%dT%H:%M')
  input_html_options[:type]         = :'datetime-local'
  input_html_options[:html5]        = true
  input_html_options[:value]        = dt_val
  input_html_options[:'data-input'] = ''
  input_html_options[:class] = [input_html_options[:class], 'pe-5'].compact.join(' ')

  if floating
    # Bootstrap floating labels require a non-absent placeholder so the
    # :not(:placeholder-shown) CSS selector fires and floats the label up.
    input_html_options[:placeholder] ||= ' '
    template.(:div, class: 'form-floating datetime_picker_wrapper date-picker_wrapper_single') do
      template.concat super(wrapper_options)
      template.concat floating_label_tag
      template.concat clear_btn
    end
  else
    template.(:div, class: 'datetime_picker_wrapper date-picker_wrapper_single d-flex align-items-center position-relative') do
      template.concat super(wrapper_options)
      template.concat clear_btn
    end
  end
end

#label(_wrapper_options = nil) ⇒ Object

In floating mode we render the label ourselves inside the wrapper (after the
input, as Bootstrap requires). Suppress SimpleForm's external label only then.



31
32
33
34
35
# File 'app/inputs/datetime_picker_input.rb', line 31

def label(_wrapper_options = nil)
  return ''.html_safe if options.fetch(:floating, false)

  super
end