1

I'm using GWT to monitor changes to a TextArea. When the user types, I catch KeyPressEvents and update my logic accordingly.

However, when the user uses the mouse to change the value of the TextArea (e.g. cut & paste or drag) I do not get KeyPressEvents (of course). I still want to update immediately. I tried ChangeEvents, but it seems that they are only fired much later, when the TextArea loses focus.

I could listen for all ClickEvents, but is there a more logical mechanism that will alert my code right after the text in a textarea changes for any reason?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Riley Lark
  • 20,660
  • 15
  • 80
  • 128
  • 2
    I guess there is not. http://stackoverflow.com/questions/3184648/instant-value-change-handler-on-a-gwt-textbox/4085371#4085371 is what I did when I came across the need to get instant feedback. Maybe helpful in your case as well. – z00bs Dec 07 '10 at 19:27
  • Have you tried "cut" and "paste" listeners? – Pointy Dec 07 '10 at 19:44
  • You want to get events when the mouse is clicked, but you don't want to listen for ClickEvents? I don't get it. – Dusty Campbell Dec 08 '10 at 01:00
  • Not all possible `ClickEvents` on the `TextArea` cause the content to change so @Riley is not really interested in all of them since only content changes matter. Listening to all `ClickEvents` and checking for changes would be a workaround but is no ideal solution. – z00bs Dec 09 '10 at 10:59
  • Thanks @z00bs, yours is the best solution I've found. – Riley Lark Dec 09 '10 at 16:39

2 Answers2

1

You could use setTimeout:

var ta = document.getElementById("yourTextarea");
var value = ta.value;

function check() {
    if ( ta.value !== value ) {
        // value has changed
        value = ta.value;
    }
    setTimeout(check, 100);
}

check();
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
0

Seems like catching the paste & cut events directly is the best way - there's no "changed-at-all" event.

Riley Lark
  • 20,660
  • 15
  • 80
  • 128