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

A field for handling a date 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 wich receives a DateTime and must return a string.

    The default value is "%Y-%m-%d".

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

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

  • :readonly - Sets the field to readonly. Also see the panels guide.

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

Summary

Functions

validate_config!(field, live_resource)