mikemaccana
mikemaccana

Reputation: 123610

Is it possible to determine the type of input from the input handler?

I have an event handler for the 'input' event:

inputEl.addEventListener('input', function(event) {
    log('yaay!')
});

I need to do something just for paste. I know I could make a separate event handler for 'paste' only, however I share code for most types of inputs and would like to avoid extra listeners if not necessary. Is it possible - for example, by checking a property of the event object, to see if a input event was initiated by pasting?

Upvotes: 3

Views: 167

Answers (1)

Sterling Archer
Sterling Archer

Reputation: 22425

From what I can see, there is no way to do that without binding a separate event listener.

The event object has no "input type" methods that I can see in the log, so just checking for an input you cannot determine if typed or pasted. It's just plain input.

For example (from a deleted answer I saw), checking say, event.type in the input listener will yield input whether you typed or pasted.

Upvotes: 4

Related Questions