0

I have textbox currently i have attached DOJO event and for every key press it is triggering event but is there any event in DOJO that should trigger only after keyboard typing is completed.

<div  class="cell">
<input type="search" name="searchbox" id="searchbox" placeholder="Search Location" data-dojo-attach-event = "keypress:_getData"/>
</div>

_getData:function(){
         alert("function triggered");    
         }

Where this keypress is the event from dojo/keys.

Currently if i type "STACK" the event is triggering 5 times instead it should trigger one time after typing full word or it should trigger only after he stops typing.

Manjunath M
  • 588
  • 1
  • 6
  • 30

1 Answers1

0

You have to use a debounce mechanism. If you use Dojo 1.10, you can do use dojo/on/debounce:

on(dom.byId('searchbox'), 'keypress', debounce(this._getData));

You can see the unit test for more details: https://github.com/dojo/dojo/blob/db66e918cd5a736fa4023741ace82e1bdc0fb612/tests/unit/on/debounce.js

ben
  • 3,558
  • 1
  • 15
  • 28