views:

223

answers:

3

I want to capture when a user pastes data into a text input field using mootools event system.

Anyone have experience of this?

A: 

Here's an answer to a similar problem.

http://stackoverflow.com/questions/2130275

Mic
A: 

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>
Zaje
don't forget you an copy/paste using ctrl+ins / shift+ins and the context menu - whereas you can trap keyboard events, a right-click / paste will work, not sure about onpaste
Dimitar Christoff
rutherford
Added the HTML and JS code.
Zaje
+1  A: 

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.

Tim Down