I want to capture when a user pastes data into a text input field using mootools event system.
Anyone have experience of this?
I want to capture when a user pastes data into a text input field using mootools event system.
Anyone have experience of this?
The function will get fired whenever the keys 'ctrl+v' are pressed.
Mootools docs : http://www.mootools.net/docs/more/Interface/Keyboard
EDIT : HTML and JS Code
<html>
<head>
<script type='text/javascript' src='core.js'></script>
<script type='text/javascript' src='more.js'></script>
<script type='text/javascript'>
function keyPressed(e)
{
var evt = Event(e);
evt.stop();
}
window.addEvent('domready', function()
{
var myKeyboardEvents = new Keyboard(
{
eventType: 'keyup',
events:
{
'ctrl+v': keyPressed
}
});
myKeyboardEvents.activate()
});
</script>
</head>
<body>
<form id='myForm'>
<input type='text' name='some' id='username' value='[email protected]'/>
</form>
</body>
</html>
The paste
event has become better supported in recent times: IE has had it since around 2000 (IE 5.5, I think), Firefox since 3.0, WebKit for a couple of years (not sure exactly when). You should use it where possible and fall back to detecting ctrl-v or shift-ins in other cases, or polling the input box's value using a timer.