Apologies if this doesn't belong.
I'm confused as to how to set onInput attributes on a model when it has the type WebData - before it gets sent to the server. Here's an example using elm-mdl. I'm not sure how to set an empty record on the initialModel with a WebData type, and when I try to update the model attributes, it's has a type WebData, so it throws an error.
I'm new to Elm, so I think I'm missing something obvious.
type alias Install =
{ pgUser : String }
install = Install ""
type alias Model =
{ mdl : Material.Model
, install : WebData Install }
initialModel : Model
initialModel =
{ mdl = Material.model
--, install = RemoteData.succeed install
, install = RemoteData.NotAsked }
type Msg = ChangePgUser String
installForm : Model -> Html Msg
installForm model = form [ Attr.id "installation__body"
, Attr.class "install__form"
, Attr.action "/install"
, Attr.method "POST" ] [ installHeader "PostgreSQL Configuration"
, Textfield.render Mdl [0] model.mdl
[ Textfield.label "PostgreSQL User"
, Textfield.floatingLabel
, Textfield.text_
, Options.id "pg-user"
, Options.attribute <| (Attr.attribute "autocomplete" "new-user")
, Options.onInput ChangePgUser
][]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ChangePgUser username ->
let
-- What to do here?
oInstall = model.install
nInstall = { oInstall | pgUser = username }
in
({ model | install = nInstall }, Cmd.none)
`oInstall` is being used in an unexpected way.
nInstall = { oInstall | pgUser = username }
Based on its definition, `oInstall` has this type:
WebData Install
But you are trying to use it as:
{ b | pgUser : a }