Class: Formulary::HtmlForm::Fields::DateInput

Inherits:
Input
  • Object
show all
Defined in:
lib/formulary/html_form/fields/date_input.rb

Direct Known Subclasses

MonthInput, WeekInput

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Input

compatible_with?, supports_required?

Methods inherited from Field

#get_value_from_data_field, #is_hidden?, #label, #name, #set_value, supports_required?

Constructor Details

#initialize(html_form, element) ⇒ DateInput

Returns a new instance of DateInput.



15
16
17
18
19
# File 'lib/formulary/html_form/fields/date_input.rb', line 15

def initialize(html_form, element)
  @html_form, @element = html_form, element
  @min = @element.attributes['min'].try('value')
  @max = @element.attributes['max'].try('value')
end

Class Method Details

.compatible_typeObject



3
4
5
# File 'lib/formulary/html_form/fields/date_input.rb', line 3

def self.compatible_type
  "date"
end

Instance Method Details

#datetime_formatObject



11
12
13
# File 'lib/formulary/html_form/fields/date_input.rb', line 11

def datetime_format
  "%Y-%m-%d"
end

#display_formatObject



7
8
9
# File 'lib/formulary/html_form/fields/date_input.rb', line 7

def display_format
  "YYYY-MM-DD"
end

#errorObject



25
26
27
28
29
30
# File 'lib/formulary/html_form/fields/date_input.rb', line 25

def error
  return super if super.present?
  return "'#{label}' is not a properly formatted #{self.class.compatible_type}, please use #{display_format}" unless date_correct?
  return "'#{label}' must be a #{self.class.compatible_type} after #{@min}" unless min_correct?
  return "'#{label}' must be a #{self.class.compatible_type} before #{@max}" unless max_correct?
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/formulary/html_form/fields/date_input.rb', line 21

def valid?
  super && date_correct? && min_correct? && max_correct?
end