View Source Backpex.Fields.DateTime (Backpex v0.8.2)

A field for handling a date time value.

Options

  • :format - Format string which will be used to format the date time value or function that formats the date time. Defaults to %Y-%m-%d %I:%M %p. If a function, must receive a DateTime and return a string.
  • :debounce - Optional integer timeout value (in milliseconds), "blur" or function that receives the assigns.
  • :throttle - Optional integer 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.Date,
      label: "Created At",
      # If you use the same formatting logic in multiple places
      format: &MyApp.Formatters.Dates/1
    }
  ]
end