Amparo
Amparo

Reputation: 824

Getting ID attribute when event is fired (subscriptions)

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

Answers (1)

bdukes
bdukes

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

Related Questions