Class: DatePickerInput

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

Overview

SimpleForm input wrapper: date picker.

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options) ⇒ Object



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
35
36
37
38
# File 'app/inputs/date_picker_input.rb', line 5

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

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

  # e.g. max_date: 'today' — any flatpickr maxDate/minDate expression
  wrapper_data = { controller: 'date-picker' }
  wrapper_data[:date_picker_max_date_value] = options[:max_date] if options[:max_date].present?
  wrapper_data[:date_picker_min_date_value] = options[:min_date] if options[:min_date].present?

  if floating
    input_html_options[:placeholder] ||= ' '
    input_html_options[:class] = [input_html_options[:class], 'form-control'].compact.join(' ')
    template.(:div, class: 'form-floating date_picker_wrapper date-picker_wrapper_single', style: style_css, data: wrapper_data) do
      template.concat super(wrapper_options)
      template.concat floating_label_tag
      template.concat clear_btn
    end
  else
    out = ActiveSupport::SafeBuffer.new
    out << template.(:div,
      class: 'date_picker_wrapper date-picker_wrapper_single d-flex align-items-center position-relative',
      style: style_css,
      data: wrapper_data) do
      template.concat super(wrapper_options)
      template.concat clear_btn
    end
    out
  end
end

#label(_wrapper_options = nil) ⇒ Object



40
41
42
43
44
# File 'app/inputs/date_picker_input.rb', line 40

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

  super
end