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 taken from user 
input in text fields.
2. There is a very valid question as to what is the proper MODEL.... should 
the model hold a Float or a String?
3. There is some commentary in this thread about just using onChange 
instead of onInput. Personally I think this is a non-question. Of course we 
should be using onInput for almost everything. Live programming is 
important and becoming expected. Unless you are hitting a server on every 
keypress of COURSE you should aim for the live UX. Even then, you should 
debounce whenever possible.
4. input type=number is a possibility but has some quirks.
5. So we are back to question #2.

If we use String for the Model type, the code feels shorter but the whole 
thing feels hacky.

If we use Float for the Model type there is a lot of processing of Result 
String String types everywhere. Even Result.andThen doesn't help the 
readability much.

What have people been using? Have you been making your models Floats or 
Strings?




On Saturday, January 21, 2017 at 7:08:04 AM UTC-8, Simon wrote:
>
> I think it is not uncommon to collect dates and float values from users.
>
> update ...
>     NewValue v -> 
>         { model | floatvalue = String.toFloat v |> Result.withDefault 0.0 }
>
> floatInput : Float -> Html Msg 
> floatInput v =
>     input 
>         [ onInput NewValue 
>         , value (toString v) 
>         ] []
>
> The problem with the above is that the moment you type the . toFloat 
> fails and you get a 0 in your model. One way around it could be to delay 
> processing of the value by using onBlur (below), but I was wondering how 
> others handled this.
>
> floatInput_ : Float -> Html Msg 
> floatInput_ v =
>     input 
>         [ onBlur NewValue 
>         , value (toString v) 
>         ] []
>
> ​
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to