-
9 Jun 2007 3:35 PM #1
Focus on button when "enter" is pressed after writing in a text box
Focus on button when "enter" is pressed after writing in a text box
I have a small LayoutDialog in which I have put the Ext.form.TextField (please note that there is no form, I am just using the form.TextField library class). I also have an "OK" button added to my LayoutDialog. What I would like to do is if some one enters the value in the text box and press "enter/return" then the "OK" button should be clicked.
Would appreciate if someone could point out if I could achieve this by just using some config option.
Side question : Is it okay to use Ext.form.TextField anywhere ?, is it meant to be used only in form ?
Regards & thanks
Kapil
-
12 Jun 2007 6:04 AM #2
Text Field, Enter/Return key config
Text Field, Enter/Return key config
Unfortunately I don't think there is a config option for this, although it would be nice to have one.
One way is to add an event handler to each Text Field.
Code might be something like this to detect the Return and Enter keys:
MaxHTML Code:var myTextField = new Ext.form.TextField( ...etc... ); myTextField.on("specialkey", specialKey, this); function specialKey( field, e ) { if ( e.getKey() == e.RETURN || e.getKey() == e.ENTER ) { //...code to submit form goes here // be careful of scope if calling your button click handler... } }
-
12 Jun 2007 8:45 AM #3
You can add listeners to the the field objects via config.
This hasn't made it into the doc yet, but here's a sample. There are several supported ways of declaring the handlers in the listeners object - see this thread.
Code:var userName = new Ext.form.TextField({ id:'userName', minLength:3, maxLength:20, allowBlank:false, blankText:'A user name is required', vtype:'alphanum', listeners:{ 'valid':this.onFieldValid, 'invalid':this.onFieldInvalid, scope:this } }); userName.applyTo('userName');Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
13 Jun 2007 12:45 AM #4
Options
Options
It would still be nice to have some of the "standard" field options built in as configuration parameters rather than have to add your own handlers.
E.g.
Enter key -> go to next field.
Enter key -> submit form
etc
Max
-
5 Jan 2008 6:05 PM #5
how about keynav?
how about keynav?
var nav = new Ext.KeyNav("my-element", {
"left" : function(e){
this.moveLeft(e.ctrlKey);
},
"right" : function(e){
this.moveRight(e.ctrlKey);
},
"enter" : function(e){
this.save();
},
scope : this
});
-
5 Mar 2008 6:27 AM #6


Reply With Quote