Only one of the events is firing on Textfield - keyup or keydown but not both.

  1. #1

    Only one of the events is firing on Textfield - keyup or keydown but not both.

    Hi
    When we attach the below as a plugin to Textfield, only the keydown eventhandler is executing, could someone please help with what is the issue here. My requirement is to be able to handle both the keydown and keyup events so that I could see both the old/new values and process accordingly.

    Ext.ux.Mask = function(mask) {
        var config = {
            mask: mask
        };
        Ext.apply(this, config);
    };
    Ext.extend(Ext.ux.Mask, Object, {
        init: function(c) {        
            c.enableKeyEvents = true;
            c.on('keydown', function(field, evt) { alert(field.getValue()); }, this);        
            c.on('keyup', function(field, evt) { alert(field.getValue()); }, this);        
        }
    });
    Last edited by geoffrey.mcgill; Oct 28, 2010 at 10:45 PM. Reason: please use [CODE] tags
  2. #2
    Hi,

    For the future please use [CODE ] tags for any code. This post we have already edited.

    See
    http://forums.ext.net/showthread.php...ing-New-Topics

    http://forums.ext.net/showthread.php...ation-Required

    When we attach the below as a plugin to Textfield, only the keydown eventhandler is executing, could someone please help with what is the issue here. My requirement is to be able to handle both the keydown and keyup events so that I could see both the old/new values and process accordingly.
    Your code appears to be correct.

    Just alert() is not a good idea to test events like "keyup", "keydown".

    The following example demonstrates that your code is fine.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <ext:ResourcePlaceHolder runat="server" />
        <script type="text/javascript">
            Ext.onReady(function() {
                TextField1.on("keydown", 
                    function() { 
                        DisplayField1.setValue("keydown"); 
                    });       
                TextField1.on("keyup", 
                    function() { 
                        DisplayField1.setValue("keyup"); 
                    });
            });
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TextField 
            ID="TextField1" 
            runat="server" 
            EnableKeyEvents="true" 
            FieldLabel="Test TextField" />
        <ext:DisplayField 
            ID="DisplayField1" 
            runat="server" 
            Text="Event here" 
            StyleSpec="color: red;"/>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Feb 20, 2011 at 12:28 PM.
  3. #3

    Thank you for the reply.

    Hi Daniil
    Thanks for your message. You are right, alerts are not the proper way to test those events.
    Other tests have shown that the keyup and keydown eventhandlers are properly getting called.

    Thanks again for your time,
    Sridhar

Similar Threads

  1. Dynamic TextField KeyUP Event
    By archana in forum 1.x Help
    Replies: 0
    Last Post: Oct 21, 2011, 6:23 AM
  2. [CLOSED] KeyDown Event Not Firing
    By JonG in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jun 04, 2010, 1:57 PM
  3. Textfield Keyup Listener Not Working
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Sep 25, 2009, 2:10 AM
  4. [CLOSED] KeyPress,KeyDown,KeyUp Events not firing
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2009, 5:08 PM
  5. [CLOSED] KeyUp and KeyPress events
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 01, 2008, 3:07 PM

Posting Permissions