Backpex.Fields.DateTime (Backpex v0.23.0)

Copy Markdown View Source

A field for handling a date time value.

Field-specific options

See Backpex.Field for general field options.

  • :format - Format string which will be used to format the date time value or function that formats the date time.

    Can also be a function which receives a DateTime and must return a string. Empty (nil) values are rendered as "—" and never passed to the function.

    The default value is "%Y-%m-%d %I:%M %p".

  • :debounce - Timeout value (in milliseconds), "blur" or function that receives the assigns.

  • :throttle - Timeout value (in milliseconds) or function that receives the assigns.

Examples

@impl Backpex.LiveResource
def fields do
  [
    created_at: %{
      module: Backpex.Fields.DateTime,
      label: "Created At",
      format: "%Y.%m.%d %I:%M %p" # optional
    }
  ]
end

@impl Backpex.LiveResource
def fields do
  [
    created_at: %{
      module: Backpex.Fields.DateTime,
      label: "Created At",
      format: fn date_time -> # Takes a `DateTime` and returns a string
        # Timex should be installed separately, used as a reference for
        # custom formatting logic.
        Timex.format!(date_time, "{relative}", :relative)
      end
    }
  ]
end

@impl Backpex.LiveResource
def fields do
  [
    created_at: %{
      module: Backpex.Fields.DateTime,
      label: "Created At",
      # If you use the same formatting logic in multiple places
      format: &MyApp.Formatters.format_datetime/1
    }
  ]
end

Summary

Functions

Returns the schema of configurable options for this field.

Functions

config_schema()

Returns the schema of configurable options for this field.

This can be useful for reuse in other field modules.