Hello, new to elm and experimenting around with it and I'm not sure how to
update a sub model. I have not run across an example of this form yet.
Given the following:
-- MODEL
type alias StringField =
{
value : String
, errors : List String
}
------> how to update value and errors fields for email and password in this
model
type alias Model =
{ email : StringField
, password : StringField
}
initValue : String
initValue = ""
initErrors : List String
initErrors = []
initEmail = StringField initValue initErrors
initPassword = StringField initValue initErrors
init : (Model, Cmd Msg)
init =
(Model initEmail initPassword, Cmd.none)
-- UPDATE
type Msg
= InputEmail String
| InputPassword String
| SubmitForm
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
InputEmail email ->
let
emailModel = model.email
in
---->>
{ emailModel | value = email, errors = validateEmail email }
( { model | email = emailModel }, Cmd.none)
InputPassword password ->
let
passwordModel = model.password
in
---->>
{ passwordModel | value = password, errors = validatePassword
password }
( { model | password = passwordModel }, Cmd.none )
SubmitForm ->
( model, Cmd.none)
validateEmail : String -> List String
validateEmail model =
--put validation here
[]
validatePassword : String -> List String
validatePassword model =
--put validation here
[]
I have worked through several iterations and got to this point but it seems
like there should be an easier and more direct way. Plus this is still
producing the following errors:
-- TYPE MISMATCH -----------------------------------------------
kitchensink.elm
You are giving an argument to something that is not a function!
63| { passwordModel | value = password, errors = validatePassword
password }
64|> ( { model | password = passwordModel }, Cmd.none )
Maybe you forgot some parentheses? Or a comma?
-- TYPE MISMATCH -----------------------------------------------
kitchensink.elm
You are giving an argument to something that is not a function!
56| { emailModel | value = email, errors = validateEmail email }
57|> ( { model | email = emailModel }, Cmd.none)
Maybe you forgot some parentheses? Or a comma?
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.