Class: Formulary::HtmlForm::Fields::DateInput
- Inherits:
-
Input
- Object
- Field
- Input
- Formulary::HtmlForm::Fields::DateInput
show all
- Defined in:
- lib/formulary/html_form/fields/date_input.rb
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_type ⇒ Object
3
4
5
|
# File 'lib/formulary/html_form/fields/date_input.rb', line 3
def self.compatible_type
"date"
end
|
Instance Method Details
11
12
13
|
# File 'lib/formulary/html_form/fields/date_input.rb', line 11
def datetime_format
"%Y-%m-%d"
end
|
7
8
9
|
# File 'lib/formulary/html_form/fields/date_input.rb', line 7
def display_format
"YYYY-MM-DD"
end
|
#error ⇒ Object
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
21
22
23
|
# File 'lib/formulary/html_form/fields/date_input.rb', line 21
def valid?
super && date_correct? && min_correct? && max_correct?
end
|