Class: DatetimePickerInput

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

Overview

SimpleForm input wrapper: datetime picker.

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
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/inputs/datetime_picker_input.rb', line 4

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

  input_html_options[:type]         = :text
  input_html_options[:placeholder] ||= 'MM/DD/YYYY HH:MM'
  input_html_options[:'data-input'] = ''
  input_html_options[:class] = [input_html_options[:class], 'pe-5'].compact.join(' ')
  style_css = input_html_options.delete(:style)

  controller_data = {
    controller: 'date-picker',
    'date-picker-enable-time-value': true,
    'date-picker-format-value': 'Y-m-d H:i',
    'date-picker-alt-format-value': 'm/d/Y h:i K'
  }

  if floating
    input_html_options[:placeholder] ||= ' '
    input_html_options[:class] = [input_html_options[:class], 'form-control'].compact.join(' ')
    template.(:div, class: 'form-floating datetime_picker_wrapper date-picker_wrapper_single', style: style_css, data: controller_data) 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', style: style_css, data: controller_data) 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.



38
39
40
41
42
# File 'app/inputs/datetime_picker_input.rb', line 38

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

  super
end