BLacika

BLacika

Onchange on number type input field

Hi there!
I have an input field with number type in a form. Behind this field is a schema field with float type.
When the value of this field change, it will run the phx-change of the form.

<.input field={{line, :quantity}} type="number" label="Quantity" step="0.01" />

When i enter only a number (e.g. 1), it throws an error:

[error] GenServer #PID<0.635.0> terminating
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a textual representation of a float

    :erlang.binary_to_float("1")

I don’t think the phx-debounce is the solution to this.
How do you avoid this error? Thank you :slight_smile:

Marked As Solved

03juan

03juan

What’s the reason for using :erlang.binary_to_float/1 instead of Float.parse/1?

iex> :erlang.binary_to_float("1")
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a textual representation of a float

    :erlang.binary_to_float("1")
    iex:2: (file)
iex> {num, _} = Float.parse("1")
{1.0, ""}
iex> num
1.0
iex> {num, _} = Float.parse("1.")
{1.0, "."}

Last Post!

03juan

03juan

No worries, I’ve made the same mistake before. I was just going off the error message but see now that String.to_float/1 inlines the :erlang function.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement