You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/backpex/fields/currency.ex
+35-39Lines changed: 35 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,23 @@ defmodule Backpex.Fields.Currency do
7
7
throttle: [
8
8
doc: "Timeout value (in milliseconds) or function that receives the assigns.",
9
9
type: {:or,[:pos_integer,{:fun,1}]}
10
+
],
11
+
unit: [
12
+
doc: "Unit to display with the currency value, e.g. '€'.",
13
+
type: :string,
14
+
default: "€"
15
+
],
16
+
radix: [
17
+
doc:
18
+
"Character used as the decimal separator, e.g. ',' or '.'. Make sure this value matches the one you've configured in your Money library.",
19
+
type: :string,
20
+
default: ","
21
+
],
22
+
thousands_separator: [
23
+
doc:
24
+
"Character used as the thousands separator, e.g. '.' or ','. Make sure this value matches the one you've configured in your Money library.",
25
+
type: :string,
26
+
default: "."
10
27
]
11
28
]
12
29
@@ -21,16 +38,14 @@ defmodule Backpex.Fields.Currency do
21
38
22
39
## Schema
23
40
24
-
`Backpex.Ecto.Amount.Type` provides a type for Ecto to store a amount. The underlying data type should be an integer.
25
-
For a full list of configuration options see: https://hexdocs.pm/money/Money.html#module-configuration
41
+
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.
26
42
27
-
schema "article" do
28
-
field :price, Backpex.Ecto.Amount.Type
29
-
...
30
-
end
43
+
Ensure that your schema field is set up to handle the currency type appropriately.
44
+
45
+
For example, if you are using the [Money](https://hex.pm/packages/money) library, your schema might look like this:
31
46
32
47
schema "article" do
33
-
field :price, Backpex.Ecto.Amount.Type, currency: :EUR, opts: [separator: ".", delimiter: ","]
48
+
field :price, Money.Ecto.Amount.Type
34
49
...
35
50
end
36
51
@@ -41,46 +56,45 @@ defmodule Backpex.Fields.Currency do
0 commit comments