artf/cimice

can not observe textarea text change but work well with input

CocaCola183 opened this issue · 1 comments

my own keyup event calback:

keyupEventCallback(recorder, movie, e) {
    let focusedElement = document.activeElement;
    focusedElement.setAttribute('value', focusedElement.value);

    const t = e.target;
    const b = t.body;
    const scrollTop = b ? (b.parentNode.scrollTop || b.scrollTop) : t.scrollTop;
    const scrollLeft = b ? (b.parentNode.scrollLeft || b.scrollLeft) : t.scrollLeft;
    movie.addFrame({
      scrollY: scrollTop,
      scrollX: scrollLeft,
      cursorX: e.pageX,
      cursorY: e.pageY,
      width: recorder.target.clientWidth,
      height: recorder.target.clientHeight,
      eventType: e.type,
    });
  }

works fun with input, but not work with textarea.

something wrong?

artf commented

I'm wondering how does it work with inputs if you aren't adding additional stuff to the frame (in addFrame)?!?

Anyway, I've tried with the keyup event and everything works as expected
From your example I'd expect something like this:

keyupEventCallback(recorder, movie, e) {
    let focusedElement = document.activeElement;
    
    // The value is already setted, you don't need this
    //focusedElement.setAttribute('value', focusedElement.value);
 
   // This, at any keyup, will show the actual value
   var actualInputValue = focusedElement.value;
   console.log(actualInputValue);

    const t = e.target;
    const b = t.body;
    const scrollTop = b ? (b.parentNode.scrollTop || b.scrollTop) : t.scrollTop;
    const scrollLeft = b ? (b.parentNode.scrollLeft || b.scrollLeft) : t.scrollLeft;
    movie.addFrame({
      scrollY: scrollTop,
      scrollX: scrollLeft,
      cursorX: e.pageX,
      cursorY: e.pageY,
      width: recorder.target.clientWidth,
      height: recorder.target.clientHeight,
      eventType: e.type,
      inputValue: actualInputValue, // <- make the frame know about the value
    });
  }

Of course, after the recorder you've also to setup the player:

player.on('keyup', function(frame){
 console.log(frame.inputValue);
 // ...
});