Reputation: 824
I have a subscription to calculate (Calculate String
msg) something when user is writing on some divs (contenteditable).
subscriptions : CvModel -> Sub Msg
subscriptions _ =
onKeyUp (Decode.succeed Calculate) -- I need add the id element in message.
But, how I can get id
attribute of the div where user is writing?
Upvotes: 1
Views: 53
Reputation: 156045
The decoder that you pass to onKeyUp
is decoding the event object, so you can extract the id
property of the target
element (much like targetValue
).
onKeyUp (Decode.at ["target", "id"] Decode.string |> Decode.map Calculate)
There's an example app at https://ellie-app.com/9MVn2Zsxptva1
Upvotes: 4