What are the valid strings for the typeArg argument of the InputEvent constructor?

731 Views Asked by At

From MDN InputEvent() docs:

event = new InputEvent(typeArg, inputEventInit);

typeArg Is a DOMString representing the name of the event.

What are the valid "names?" I can't find any resources indicating this. I want to replicate a typing event for my tests.

2

There are 2 best solutions below

4
Andrew Li On BEST ANSWER

This is listed in Section 5.2 of the Input Events Level 2 Specification and are input and beforeInput. This is also listed in Section 4.5.3 of the UI Events Specification.

0
xquilt On

the InputEvent is an object particularly inheriting all the properties that has to do with form events

which are : submit , change , input

so a use case would be revealing one of those properties of any of the InputEvent events

var input = document.getElementById("textarea") ;
 
input.addEventListener("input", function(e) {
  console.log(e.inputType) ; 
})

or in this case creating a new custom input event and fire it multiple times in a loop

var inputField = document.getElementById("textarea") ;
var newInput = new InputEvent("input") ; 

for (var i = 0 ; i < 10 ; i ++ ) {
  inputField.value += i + "\n" ; 
  inputField.dispatchEvent(newInput) ; 
  
}