Search code examples
javascriptcopy-pastemootoolspastemootools-events

Is there a way to capture x-browser paste events in mootools?


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

Anyone have experience of this?


Solution

  • 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>