[elm-discuss] Re: Forms with Floats / Dates

2017-07-25 Thread Vlad GURDIGA
Hi Simon! As a newcomer to Elm, I too have this issue fresh in my experience, and my approach has been similar to what Witold Szczerba’s: I’ve built myself a MyDate type to hold all the

[elm-discuss] Re: Forms with Floats / Dates

2017-07-22 Thread Ray Toal
Has there been any consensus on this question. I would _love_ to know if there is a preferred Elm style for this. It seems like a very big deal. Here's what I can glean from the thread so far. (I hope this post reactivates the discussion.) 1. Floats and Dates and other such things are commonly

[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon
That’s the way the virtual dom works, the view is rewritten on every loop To be honest, I thought the exact opposite was the case - only bits that have changed are rewritten? Meanwhile defaultValue a perfect solution @Witold: I can see how your solution works in some cases where you have

Re: [elm-discuss] Re: Forms with Floats / Dates

2017-01-22 Thread Witold Szczerba
Hi, this is my humble solution to this problem: https://runelm.io/c/a7u In my application, I did not have to deal with numbers in forms, but I was using "form" types like this: type alias TextField = { value: String, error: String } The validation was performed on update and form error messages

[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Bernardo
That's the way the virtual dom works, the view is rewritten on every loop. You need to change line 49 to HA.defaultValue (toString model). On Sunday, 22 January 2017 06:28:43 UTC-3, Simon wrote: > > Here is an example of the problem > https://runelm.io/c/5nk > > > > On Sunday, 22 January 2017

[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon
Here is an example of the problem https://runelm.io/c/5nk On Sunday, 22 January 2017 10:22:34 UTC+1, Simon wrote: > > So my problem has evolved. I can see that onChange would work, but I am > also subscribing to KeyBoard.presses. As a result every keypress is > firing the update function

[elm-discuss] Re: Forms with Floats / Dates [DOM diffing issue]

2017-01-22 Thread Simon
So my problem has evolved. I can see that onChange would work, but I am also subscribing to KeyBoard.presses. As a result every keypress is firing the update function even while onChange is waiting for a blur. That shouldn’t be an issue I thought. If the key press does not change the part

[elm-discuss] Re: Forms with Floats / Dates

2017-01-22 Thread Simon
Hi, your idea looked interesting until I tried it. https://runelm.io/c/y3g Try entering a number and then backspacing to delete it. I could not get rid of the first digit I thought onChange would do it, but my early tests seem to suggest that it is firing just as often as onInput, which

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread Bernardo
This is an improvement, but again, trying to validate on every key press causes problems. Type a number and you can't delete it with backspace, you can't enter a negative number, ctrl-z acts weird. Now, I'm sure you can work around all of these problems, but why don't wait until the user has

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread j weir
Even simpler is to just use input [] [type_ "number"] any reasons not to? http://caniuse.com/#feat=input-number https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164 On Saturday, January 21, 2017 at 1:37:16 PM UTC-8, j weir wrote: > > You could also format the input so it is always a

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread j weir
You could also format the input so it is always a decimal. And instead of using Result.withDefault 0.0, revert to the existing value. This way the input won't be destroyed if the user fat fingers a non numeral. https://gist.github.com/jweir/9e8412a4fa0132866977626e337cb164 On Saturday,

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread Rafał Cieślak
I'd consider storing the whole string in the model and passing it to value. This way you can capture whatever input the user types and convert it to float only when you actually need to do something with the float. IMHO because the input tag allows you to type any kind of string, you should

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread Bernardo
Instead of onInput I listen to the *change *event so I don't validate and update the model on every key press. In most cases I don't see a reason to update the model on every key press. On Saturday, 21 January 2017 12:16:03 UTC-3, Simon wrote: > > Correction > > toString (toFloat "5.") == "5"

[elm-discuss] Re: Forms with Floats / Dates

2017-01-21 Thread Simon
Correction toString (toFloat "5.") == "5"-i.e. the `.` gets stripped off so you can never actually add decimal values On Saturday, 21 January 2017 16:08:04 UTC+1, Simon wrote: > > I think it is not uncommon to collect dates and float values from users. > > update ... > NewValue v ->