Module: StimulusPlumbers::Form::Fields::Inputs::Datetime

Included in:
Builder
Defined in:
lib/stimulus_plumbers/form/fields/inputs/datetime.rb

Instance Method Summary collapse

Instance Method Details

#date_field(attribute, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/stimulus_plumbers/form/fields/inputs/datetime.rb', line 8

def date_field(attribute, options = {})
  html_native   = options.delete(:html_native) { false }
  icon_leading  = options.delete(:icon_leading)
  icon_trailing = options.delete(:icon_trailing) { "calendar" }
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    if html_native
      html_options = merge_html_options(opts, html_opts, field_theme(:form_input, error: error))
      super(attribute, html_options)
    else
      render_date_combobox(attribute, html_opts, error, icon_leading: icon_leading, icon_trailing: icon_trailing)
    end
  end
end

#time_field(attribute, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stimulus_plumbers/form/fields/inputs/datetime.rb', line 26

def time_field(attribute, options = {})
  html_native   = options.delete(:html_native) { false }
  format        = options.delete(:format) { :h12 }
  step          = options.delete(:step) { 1 }
  icon_leading  = options.delete(:icon_leading)
  icon_trailing = options.delete(:icon_trailing) { "clock" }
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    if html_native
      html_options = merge_html_options(opts, html_opts, field_theme(:form_input, error: error))
      super(attribute, html_options)
    else
      render_time_combobox(
        attribute,
        html_opts,
        error,
        format:        format,
        step:          step,
        icon_leading:  icon_leading,
        icon_trailing: icon_trailing
      )
    end
  end
end