I have an input like this :
input [ type' "number", onInput NewValue ] [ text <| toString model.value ]
How to update the model ? I have something like this:
NewValue nb ->
( { model | value = nb }, Cmd.none )
I don't know if in input type number the value is an Int
or a String
.
I also try this:
NewValue nb ->
let
nb = Result.withDefault 0 (String.toInt nb)
in
( { model | value = nb }, Cmd.none )
WIth the second version I got this error:
The return type of function `withDefault` is being used in unexpected ways.
44| nb = Result.withDefault 0 (String.toInt nb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The function results in this type of value:
Int
Which is fine, but the surrounding context wants it to be:
String
Change the function name nb to something else as it is already assigned as a String and you can't overwrite it.
NewValue nb ->
let
newInt = Result.withDefault 0 (String.toInt nb)
in
( { model | value = newInt }, Cmd.none )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With