Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created June 1, 2011 14:03
Show Gist options
  • Save phiggins42/1002345 to your computer and use it in GitHub Desktop.
Save phiggins42/1002345 to your computer and use it in GitHub Desktop.
dojo.onEnterPress = function(ref, context, method){
// summary: Shorthand utility function for hooking up enter-key handling to a text input.
var ENTER = dojo.keys.ENTER, callback = method ? dojo.hitch(context, method) : context, ev = "keypress";
if(typeof ref == "string"){
ref = dojo.byId(ref);
}else if(ref && ref.declaredClass){
ev = "onKeyPress";
}
return dojo.connect(ref, ev, function(e){
e && e.charOrCode && e.charOrCode == ENTER && callback();
});
};
// example, call this._runSearch() when they hit enter in a textbox or on the search button:
dojo.onEnterPress(widget, this, "_runSearch");
dojo.connect(button, "onClick", this, "_runSearch");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment