1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Answers
    16
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default Answered: time system in sencha

    Answered: time system in sencha


    Hello, is there a time system in sencha for get Keys ?

    I have a search field, and i would like to get the key of the user, if he don't push the send request button every 1 or 2 seconds ....
    if he don't really know what to write, he can write one or two letter and thinking, and i would like to send the PHP file who get the answer request at this moment,


    a sort of auto completion system ....

  2. You want to define the delayed task only once. Think of it as a function but with a time check on it so that if the function is called repeatedly, it is buffered for the period of time you specify. So, in your code that I have done a little restructuring on below...
    I have added a render listener, which is fired only one time. at that time, i instantiate the DelayedTask and store it as a member of the search field itself. Then, in the keyup event, i activate the delayed task with a 500ms buffer, meaning that if i type really fast it wont fire until i stop typing for 500 ms...
    I commented out your actual logic because i obviously dont have the controllers invoked, so you will want to add that back in, however, it is noteworthy, that the Ext.dispatch is placed inside the DelayedTask function itself. That means that after the 500ms delay, this logic will fire

    Code:
                {                xtype: 'searchfield',
                    style: 'margin-right: 10px;',
                    listeners: {
                        'render': function(fld){
                            fld.task = new Ext.util.DelayedTask(function() {
                                alert(fld.getValue());
    //                    Ext.dispatch({
    //                        controller: WPApp.controllers.searchController,
    //                        action: 'doSearchCompletion',
    //                        data: query
    //                    });
                            });
    
    
                        },
                        keyup: function(thisField, e) {
                            var query = thisField.getValue();
                            if (e.browserEvent.keyCode == 13) {
    //                            Ext.dispatch({
    //                                controller: WPApp.controllers.searchController,
    //                                action: 'doSearchValidate',
    //                                data: query
    //                            });
                            }
                            else {
                                thisField.task.delay(500);
                            }
                        }
                    }
                }
    one additional note that I might suggest is to try to avoid hard setting of ids. Notice how i was able to eliminate them completely from the code... just a friendly suggestion that will be of benefit to you down the road.

    Also, in the if block where you check for keycode of 13, you may want to cancel the task. So, if you type a bunch of characters and then hit enter, if you want to cancel the execution of the delayed task, put this as the first line of the if condition...but you will have to decide what sort of behavior you want in that if condition.


    thisField.task.cancel();

  3. #2
    Sencha Premium Member
    Join Date
    May 2008
    Location
    Pasadena, California
    Posts
    172
    Answers
    27
    Vote Rating
    2
    NickT is on a distinguished road

      0  

    Default


    Hello,
    what you are looking for is the Ext.util.DelayedTask. It allows you to attach a function to an event and it buffers all invocations of that event and only fires the last one. So, for instance, if you set a delayed task to buffer for 5 seconds and you attached it to the search field keyup event, then if someone was typing it would not fire until someone stopped typing for 5 seconds...

    here is a simple example of its usage. Refer to the API docs for a full description...

    Code:
    var task = new Ext.util.DelayedTask(function(){    alert(Ext.getDom('myInputField').value.length);
    });
    // Wait 500ms before calling our function. If the user presses another key
    // during that 500ms, it will be cancelled and we'll wait another 500ms.
    Ext.get('myInputField').on('keypress', function(){
        task.delay(500);
    });

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Answers
    16
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default


    Hum, i tried but, don't work ... don't know:

    Code:
    items: [
    		{	
    			flex: 1,
    			xtype: 'searchfield',
    			style: 'margin-right: 10px;',
    			id: WPApp.config._SearchIdTextField,
    			listeners: {
    				keyup: function(thisField, e) {
    					var query = Ext.getCmp(WPApp.config._SearchIdTextField).getValue();
    					if (e.browserEvent.keyCode == 13) {
    						Ext.dispatch({
    							controller: WPApp.controllers.searchController,
    							action: 'doSearchValidate',
    							data: query,
    						});
    					}
    					else {
    
                           var task = new Ext.util.DelayedTask(function(){                                alert(Ext.getDom(WPApp.config._SearchIdTextField).value.length);                       });                       Ext.get(WPApp.config._SearchIdTextField).on('keypress', function(){                            task.delay(500);                        });                                         Ext.dispatch({
    							controller: WPApp.controllers.searchController,
    							action: 'doSearchCompletion',
    							data: query,
    						});
    					}
    				}
    			}
    		},
    It mist display me the alert ?

  5. #4
    Sencha Premium Member
    Join Date
    May 2008
    Location
    Pasadena, California
    Posts
    172
    Answers
    27
    Vote Rating
    2
    NickT is on a distinguished road

      0  

    Default


    You want to define the delayed task only once. Think of it as a function but with a time check on it so that if the function is called repeatedly, it is buffered for the period of time you specify. So, in your code that I have done a little restructuring on below...
    I have added a render listener, which is fired only one time. at that time, i instantiate the DelayedTask and store it as a member of the search field itself. Then, in the keyup event, i activate the delayed task with a 500ms buffer, meaning that if i type really fast it wont fire until i stop typing for 500 ms...
    I commented out your actual logic because i obviously dont have the controllers invoked, so you will want to add that back in, however, it is noteworthy, that the Ext.dispatch is placed inside the DelayedTask function itself. That means that after the 500ms delay, this logic will fire

    Code:
                {                xtype: 'searchfield',
                    style: 'margin-right: 10px;',
                    listeners: {
                        'render': function(fld){
                            fld.task = new Ext.util.DelayedTask(function() {
                                alert(fld.getValue());
    //                    Ext.dispatch({
    //                        controller: WPApp.controllers.searchController,
    //                        action: 'doSearchCompletion',
    //                        data: query
    //                    });
                            });
    
    
                        },
                        keyup: function(thisField, e) {
                            var query = thisField.getValue();
                            if (e.browserEvent.keyCode == 13) {
    //                            Ext.dispatch({
    //                                controller: WPApp.controllers.searchController,
    //                                action: 'doSearchValidate',
    //                                data: query
    //                            });
                            }
                            else {
                                thisField.task.delay(500);
                            }
                        }
                    }
                }
    one additional note that I might suggest is to try to avoid hard setting of ids. Notice how i was able to eliminate them completely from the code... just a friendly suggestion that will be of benefit to you down the road.

    Also, in the if block where you check for keycode of 13, you may want to cancel the task. So, if you type a bunch of characters and then hit enter, if you want to cancel the execution of the delayed task, put this as the first line of the if condition...but you will have to decide what sort of behavior you want in that if condition.


    thisField.task.cancel();

  6. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Answers
    16
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default


    Hum yes okey, it's working, and exactly what i want. Thanks.

    Okey, i notate for the id's it's not very good to put raw value.

    Thanks

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar