Backpex.Fields.Currency (Backpex v0.16.1)

View Source

A field for handling a currency value.

Field-specific options

See Backpex.Field for general field options.

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

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

  • :unit (String.t/0) - Unit to display with the currency value, e.g. '€'. The default value is "$".

  • :unit_position - Position of the unit relative to the value, either :before or :after. The default value is :before.

  • :symbol_space (boolean/0) - Add space between the symbol and the number. The default value is false.

  • :radix (String.t/0) - Character used as the decimal separator, e.g. ',' or '.'. Make sure this value matches the one you've configured in your Money library. The default value is ".".

  • :thousands_separator (String.t/0) - Character used as the thousands separator, e.g. '.' or ','. Make sure this value matches the one you've configured in your Money library. The default value is ",".

Schema

Backpex expects you to use a Money library or a similar approach for handling currency values and dumping / casting them correctly in your database schema.

Ensure that your schema field is set up to handle the currency type appropriately.

For example, if you are using the Money library, your schema might look like this:

schema "article" do
  field :price, Money.Ecto.Amount.Type
  ...
end

Example

@impl Backpex.LiveResource
def fields do
  [
    price: %{
      module: Backpex.Fields.Currency,
      label: "Price",
      unit: "€",
      radix: ",",
      thousands_separator: "."
    }
  ]
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.