trouble adding a keyListener to textfield
var sname = new Ext.form.TextField({
id: 'sname',
fieldLabel: '', labelSeparator: '',
name: 'sname',
width:270,
allowBlank: false
})
// could not get this to work
sname.addKeyListener( 13, submitSearch );
// alternate solution I found
sname.on( 'specialkey', function (obj,e) {
if ( e.getKey() == e.RETURN ) { submitSearch(); }
});
Is addKeyListener not available to textfields?
I've tried:
* the textfield object itself, (object doesn't support this method ..)
* the .el property of the texfield (el is null or not an object),
* Ext.get('sname').addKeyListener ( ditto )
* Ext.getCmp('sname').addKeyListener ( object doesn't support this method ..)
with no joy. I realize this seems a bit desperate :D
but would anyone share the appropriate code epigram with me?
In general, using the docs to track down the availability of the more common methods
(eg those in Element) has been hit and miss for me.
Assuming I'm not just stupid and have missed something obvious,
why isn't a textfield object an Element (and thus have addKeyListener)?
thanks,
--dan
For a field, using "specialkey" is the way to go. However, if you really want to use the key listener, you just have to wait until the field is rendered and "el" exists:
sname.render(...);
sname.getEl().addKeyListener(...);
or, probably better but more code:
sname.on('render', function(){
sname.getEl().addKeyListener(...);
});
will help quite a bit as I dig deeper into the docs.
--dan
#If you have any other info about this subject , Please add it free.# |

