1. #1
    Ext User
    Join Date
    Nov 2007
    Posts
    5
    Vote Rating
    0
    utopian is on a distinguished road

      0  

    Question How to add the onkeyup event to a TextField object?

    How to add the onkeyup event to a TextField object?


    Hi,
    I've tried the following, but the onkeyup event doesn't seem to fire for the TextField object?

    Code:
    new Ext.form.TextField({
      emptyText:'insert name',
      listeners: {
        'onkeyup': function(obj) {
          alert('test fire');
        }
      }
    }),
    Any pointers appreciated.
    Last edited by JeffHowden; 12 Nov 2007 at 9:25 PM. Reason: please use CODE tags.

  2. #2
    Sencha - Community Support Team JeffHowden's Avatar
    Join Date
    Mar 2007
    Location
    Forest Grove, OR
    Posts
    1,038
    Vote Rating
    1
    JeffHowden is on a distinguished road

      0  

    Default


    Unfortunately, the TextField class does not expose the onkeydown, onkeypress, or onkeyup events from the underlying input. Fortunately, I have an override that'll expose them for you.

    http://extjs.com/forum/showthread.php?t=17532
    Jeff Howden
    Ext JS - Support Team Volunteer
    jeff@extjs.com

    Any and all code samples that are authored by me and posted on the Ext forums or website are hereby released into the public domain and I release anyone or entity of liability by using said code samples unless explicitly stated otherwise.

    Opinions are mine and not necessarily endorsed by Ext, LLC. Please do not contact me directly for assistance unless requested by me.

  3. #3
    Ext User
    Join Date
    Nov 2007
    Posts
    5
    Vote Rating
    0
    utopian is on a distinguished road

      0  

    Default


    thanks Jeff.
    It's worked (the keyup gets fired). Maybe my understanding of event buffering is wrong (I'm a newbie), but event buffering doesn't seem to work?
    After the buffering delay period, the event gets fired in consecutive succession (if I enter 5 characters during the event buffering, the alert gets displayed 5 times)

    Code:
    <snip>
    
    new Ext.form.TextField({
    	emptyText:'insert name',
    	listeners: {
    		'keyup': {
    			fn: function(obj) {
    				alert('test');
    			},
    			delay: 1000
    		}
    		}
    }),			
    						
    <snip>

  4. #4
    Sencha - Community Support Team JeffHowden's Avatar
    Join Date
    Mar 2007
    Location
    Forest Grove, OR
    Posts
    1,038
    Vote Rating
    1
    JeffHowden is on a distinguished road

      0  

    Default


    Maybe what you want is the buffer property of the config, instead of the delay.
    Jeff Howden
    Ext JS - Support Team Volunteer
    jeff@extjs.com

    Any and all code samples that are authored by me and posted on the Ext forums or website are hereby released into the public domain and I release anyone or entity of liability by using said code samples unless explicitly stated otherwise.

    Opinions are mine and not necessarily endorsed by Ext, LLC. Please do not contact me directly for assistance unless requested by me.

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,666
    Vote Rating
    586
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      1  

    Default


    As Jeff suggested, delay merely adds an extra time period before the event is fired. From the docs:

    * delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.
    * buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.

  6. #6
    Ext User
    Join Date
    Nov 2007
    Posts
    5
    Vote Rating
    0
    utopian is on a distinguished road

      0  

    Default


    Thanks heaps guys - that did it!
    Glad this forum exists!

  7. #7
    Sencha User chrizmaster's Avatar
    Join Date
    Feb 2009
    Location
    Australia
    Posts
    441
    Vote Rating
    1
    chrizmaster is on a distinguished road

      0  

    Default


    hi,
    i tried this and it works good,

    but now i want to recognize which key was pressed, but i got some errors. anyone has a solution for that?

    PHP Code:
        ,listeners: {
            
    'keyup': {
                
    fn: function(key) {
                if (
    key.getKey() == key.ENTER) {
                    
    alert('test');
                }
                } 

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      1  

    Default


    http://extjs.com/deploy/dev/docs/?cl...d&member=keyup

    Exactly what arguments does your handler get passed?

  9. #9
    Sencha User chrizmaster's Avatar
    Join Date
    Feb 2009
    Location
    Australia
    Posts
    441
    Vote Rating
    1
    chrizmaster is on a distinguished road

      0  

    Default


    well thank you, this is my working solution

    PHP Code:
        ,listeners: {
            
    'keyup': {
                
    fn: function(field,key) {
                if (
    key.getKey() == key.ENTER) {
                    
    alert('test');
                }
                } 
    I'm wondering why the keyevents are disabled by default, cause this is something, you really need everywhere. has it something to do with saving memory or something?

    Chriz

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      1  

    Default


    You don't really need it everywhere though.