Class: Effective::FormInputs::DatetimeField

Inherits:
Effective::FormInput show all
Defined in:
app/models/effective/form_inputs/datetime_field.rb

Direct Known Subclasses

DateField, TimeField

Constant Summary

Constants inherited from Effective::FormInput

Effective::FormInput::BLANK, Effective::FormInput::DEFAULT_FEEDBACK_OPTIONS, Effective::FormInput::DEFAULT_INPUT_GROUP_OPTIONS, Effective::FormInput::EMPTY_HASH, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES, Effective::FormInput::HORIZONTAL_LABEL_OPTIONS, Effective::FormInput::HORIZONTAL_WRAPPER_OPTIONS, Effective::FormInput::INLINE_LABEL_OPTIONS, Effective::FormInput::VERTICAL_WRAPPER_OPTIONS

Instance Attribute Summary

Attributes inherited from Effective::FormInput

#name, #options

Instance Method Summary collapse

Methods inherited from Effective::FormInput

#feedback_options, #hint_options, #initialize, #label_options, #to_html, #wrapper_options

Constructor Details

This class inherits a constructor from Effective::FormInput

Instance Method Details

#build_input(&block) ⇒ Object



23
24
25
# File 'app/models/effective/form_inputs/datetime_field.rb', line 23

def build_input(&block)
  @builder.super_text_field(name, options[:input].merge(value: datetime_to_s))
end

#datetime_to_sObject

ruby



27
28
29
# File 'app/models/effective/form_inputs/datetime_field.rb', line 27

def datetime_to_s # ruby
  (value&.strftime(am_pm? ? '%F %I:%M %p' : '%F %H:%M') rescue nil)
end

#formatObject

moment.js



35
36
37
# File 'app/models/effective/form_inputs/datetime_field.rb', line 35

def format # moment.js
  am_pm? ? 'YYYY-MM-DD LT' : 'YYYY-MM-DD HH:mm'
end

#input_group_optionsObject



19
20
21
# File 'app/models/effective/form_inputs/datetime_field.rb', line 19

def input_group_options
  { input_group: { class: 'input-group effective_date_time_picker_input_group' }, prepend: (:span, icon('calendar'), class: 'input-group-text') }
end

#input_html_optionsObject



7
8
9
10
11
12
13
# File 'app/models/effective/form_inputs/datetime_field.rb', line 7

def input_html_options
  {
    class: ['form-control', 'effective_date_time_picker', 'effective_datetime', ('not-date-linked' if not_date_linked?)].compact.join(' '),
    pattern: pattern,
    id: tag_id
  }
end

#input_js_optionsObject



15
16
17
# File 'app/models/effective/form_inputs/datetime_field.rb', line 15

def input_js_options
  { format: format, sideBySide: true, showTodayButton: false, showClear: false, useCurrent: 'hour', disabledDates: disabled_dates.presence, minDate: min_date.presence, maxDate: max_date.presence, locale: I18n.locale }.compact
end

#patternObject

html



31
32
33
# File 'app/models/effective/form_inputs/datetime_field.rb', line 31

def pattern # html
  am_pm? ? '\d{4}(-\d{2})?(-\d{2})?( \d{1,2})?(:\d{2} [aApPmM]{2})?' : '\d{4}(\-d{2})?(-\d{2})?( \d{2})?(:\d{2})?'
end