How to access the pasted clipboard value

Hi,

I was trying to use the onpaste event with a textarea element to access the clipboard’s content. I wrote a custom event handler but then I got stuck when I was about to find a way to decode the pasted value. I cannot simply access it through an object key like how Html.Events.targetValue works, I need to call the method event.clipboardData.getData("text"). How’s this this possible with Elm?

I cannot use ports here because I’m in the view layer. The only viable solution that comes to my mind is to create a custom element based on the TextareaElement and handle the paste event there. Is this really the way to do this?

1 Like

You’re correct that creating a custom element is the way to do it. Probably where the custom element listens to the paste event and emits a new CustomEvent with the pasted data and you Elm code listens to that custom event.

3 Likes

Exacltly as @wolfadex describes, I have some code for a custom element that does just that:

3 Likes

Thanks for the ideas.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.