Search code examples
javascriptfirefoxeventsprototypejsdom-events

Why does console show e.explicitOriginalTarget.value as set on paste or cut event in prototype.js but evaluate as empty string


check out this JSFiddle in firefox for an example

open up console and enter input into one of the fields, if you then cut the text out, check the values in console.

If you console.log(e.explicitOriginalTarget); you can see it contains a property called value that indeed contains the new correct value after cut for the input. However, on the very next line, if you try to directly console.log(e.explicitOriginalTarget.value); ,the property, the previous value of the input as it was before the cut is logged.

No idea how this is happening? Any one have any ideas?

I've tried doing a typeof e.explicitOriginalTarget.value and it is returning "string" which I expect.

If anyone can think of any other idea on how to check whether an input had all text removed on a cut I'm open to those as well. I'm kind of being forced to use prototype here and am relatively new to it so I might be overlooking some built in functionality.


Solution

  • The spec says:

    The cut event fires before the selected data is removed.

    Hence, when the event fires, the .value will be still the one before the cut. If you console.log the event/event target and later inspect it (by clicking on it ;), the change of course will have been made as the event is long done processing at this point. Remember: The target you're logging is a live DOM node.

    I'd have a setTimeout(..., 0) to check what the value is like after the cut as a stupidly easy work-around.

    Or work with input instead of cut events, if my requirements allowed that...