Class: TimePickerInput

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

Overview

SimpleForm input wrapper: time-only flatpickr picker. Shows the time in
12-hour AM/PM format to the user but submits 24-hour HH:MM to the server
(what Event#start_time_of_day and friends expect).

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options) ⇒ Object



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
# File 'app/inputs/time_picker_input.rb', line 6

def input(wrapper_options)
  input_html_options[:type] = :text
  input_html_options[:placeholder] ||= 'HH:MM AM'
  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-no-calendar-value': true,
    'date-picker-format-value': 'H:i',
    'date-picker-alt-format-value': 'h:i K'
  }

  out = ActiveSupport::SafeBuffer.new
  out << template.(:div,
    class: 'time_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
  out
end