Catch paste input
OK, just bumped into the same issue.. I went around the long way
$('input').on('paste', function () {
var element = this;
setTimeout(function () {
var text = $(element).val();
// do something with text
}, 100);
});
Just a small timeout till .val() func can get populated.
E.
You can actually grab the value straight from the event. Its a bit obtuse how to get to it though.
Return false if you don't want it to go through.
$(this).on('paste', function(e) {
var pasteData = e.originalEvent.clipboardData.getData('text')
});
For cross platform compatibility, it should handle oninput and onpropertychange events:
$ (something).bind ("input propertychange", function (e) {
// check for paste as in example above and
// do something
})
I sort of fixed it by using the following code:
$("#editor").live('input paste',function(e){
if(e.target.id == 'editor') {
$('<textarea></textarea>').attr('id', 'paste').appendTo('#editMode');
$("#paste").focus();
setTimeout($(this).paste, 250);
}
});
Now I just need to store the caret location and append to that position then I'm all set... I think :)
Hmm... I think you can use e.clipboardData
to catch the data being pasted. If it doesn't pan out, have a look here.
$(this).live("paste", function(e) {
alert(e.clipboardData); // [object Clipboard]
});