View Source Backpex.Fields.Date (Backpex v0.8.1)

A field for handling a date value.

Options

  • :format - Format string which will be used to format the date value or function that formats the date. Defaults to %Y-%m-%d. If a function, must receive a Date 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.Date,
      label: "Created At",
      format: "%d.%m.%Y"
    }
  ]
end

@impl Backpex.LiveResource
def fields do
  [
    created_at: %{
      module: Backpex.Fields.Date,
      label: "Created At",
      format: fn date -> # Takes a `Date` and returns a string
        # Timex should be installed separately, used as a reference for
        # custom formatting logic.
        Timex.format!(date, "{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