Skip to content

Commit

Permalink
Merge pull request #541 from naymspace/feature/make-formatting-optional
Browse files Browse the repository at this point in the history
Remove automatic formatting of integer values
  • Loading branch information
Flo0807 authored Aug 26, 2024
2 parents 300cbde + cca41d7 commit d3fe381
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion demo/lib/demo_web/live/post_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ defmodule DemoWeb.PostLive do
_assigns ->
true
end,
searchable: true
searchable: true,
render: fn assigns ->
~H"""
<p><%= Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".") %></p>
"""
end
},
user: %{
module: Backpex.Fields.BelongsTo,
Expand Down
5 changes: 5 additions & 0 deletions demo/lib/demo_web/live/product_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ defmodule DemoWeb.ProductLive do

error ->
error
end,
render: fn assigns ->
~H"""
<p><%= Number.Delimit.number_to_delimited(@value, precision: 0, delimiter: ".") %></p>
"""
end
},
price: %{
Expand Down
5 changes: 1 addition & 4 deletions lib/backpex/html/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Backpex.HTML do
"—"
iex> Backpex.HTML.pretty_value(1_000_000)
"1.000.000"
1000000
iex> Backpex.HTML.pretty_value(1.11)
1.11
Expand All @@ -27,8 +27,5 @@ defmodule Backpex.HTML do

def pretty_value(""), do: "—"

def pretty_value(input) when is_integer(input),
do: Number.Delimit.number_to_delimited(input, precision: 0, delimiter: ".")

def pretty_value(input), do: input
end

0 comments on commit d3fe381

Please sign in to comment.