Class: Avo::Fields::DateField
- Defined in:
- lib/avo/fields/date_field.rb
Direct Known Subclasses
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#first_day_of_week ⇒ Object
readonly
Returns the value of attribute first_day_of_week.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#picker_format ⇒ Object
readonly
Returns the value of attribute picker_format.
-
#relative ⇒ Object
readonly
Returns the value of attribute relative.
Attributes inherited from TextField
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #updatable, #user, #view, #visible
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #formatted_value ⇒ Object
-
#initialize(id, **args, &block) ⇒ DateField
constructor
A new instance of DateField.
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #fill_field, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ DateField
Returns a new instance of DateField.
9 10 11 12 13 14 15 16 |
# File 'lib/avo/fields/date_field.rb', line 9 def initialize(id, **args, &block) super(id, **args, &block) @first_day_of_week = args[:first_day_of_week].present? ? args[:first_day_of_week].to_i : 0 @picker_format = args[:picker_format].present? ? args[:picker_format] : "Y-m-d" @format = args[:format].present? ? args[:format] : :long @relative = args[:relative].present? ? args[:relative] : false end |
Instance Attribute Details
#first_day_of_week ⇒ Object (readonly)
Returns the value of attribute first_day_of_week.
4 5 6 |
# File 'lib/avo/fields/date_field.rb', line 4 def first_day_of_week @first_day_of_week end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
6 7 8 |
# File 'lib/avo/fields/date_field.rb', line 6 def format @format end |
#picker_format ⇒ Object (readonly)
Returns the value of attribute picker_format.
5 6 7 |
# File 'lib/avo/fields/date_field.rb', line 5 def picker_format @picker_format end |
#relative ⇒ Object (readonly)
Returns the value of attribute relative.
7 8 9 |
# File 'lib/avo/fields/date_field.rb', line 7 def relative @relative end |
Instance Method Details
#formatted_value ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/avo/fields/date_field.rb', line 18 def formatted_value return if value.blank? if @format.is_a?(Symbol) value.to_s(@format) else value.strftime(@format) end end |