Class: Avo::Fields::DateField

Inherits:
TextField show all
Defined in:
lib/avo/fields/date_field.rb

Direct Known Subclasses

DateTimeField

Defined Under Namespace

Classes: EditComponent, IndexComponent, ShowComponent

Instance Attribute Summary collapse

Attributes inherited from TextField

#as_html, #link_to_resource

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

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

#field_name, #get_field_name

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_weekObject (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

#formatObject (readonly)

Returns the value of attribute format.



6
7
8
# File 'lib/avo/fields/date_field.rb', line 6

def format
  @format
end

#picker_formatObject (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

#relativeObject (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_valueObject



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