Closed rande closed 6 years ago
You can identify an input by it's uid
field, so you can do:
In the messages:
InputEmail String Ui.Input.Msg
In the view:
Html.map (InputEmail input.uid) (Ui.Input.view input)
And in the update:
InputEmail uid msg ->
let
foldEmail ( commands, emails ) input =
if input.uid == uid then
let
( command, updatedInput ) = Ui.Input.update msg input
in
( Sub.batch [ commands, command ], updatedInput :: emails )
else
( commands, input :: emails )
( cmd, emails ) =
List.foldl foldEmail ( Cmd.none, [] ) model.emails
in
( { model | emails = emails }, cmd )
@gdotdesign thanks for your reply, I adjust your code to match the demo. However there is an issue with the view update, the DOM is correctly updated, however the page still display the wrong value, see the small demo:
Here the code : https://gist.github.com/rande/1827b8760a8bff39bed6a588ff7eeb66#file-test-elm-L89-L104
Ui.Input
˛just tracks the value it does not set it, in the case above when you remove an input it does not actually remove it from the DOM (it actually removes the last row) so the value remains the same.
You need to use Html.Keyed
http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html-Keyed which tracks the elements with an ID (the first tuple) so when the element with that ID is removed it actually removes the corresponding DOM elements:
Html.Keyed.node "div" []
("row-" ++ input.uid
, node "div" [] [Html.map (InputEmail input.uid) (Ui.Input.view input), button])
@gdotdesign thanks for help
for the record, here the final version https://gist.github.com/rande/556e7f920f2a3791103cb56968dc5a18
Hello,
I would like to generate a form with a list of emails with an add and remove button. Every thing is working properly. However, I cannot update the value as there is no way (as far as I know) to create a Msg with a reference to find the correct input.
Did I forgot something ? Thanks.