PDA

View Full Version : How do I attach an event handler to a textfield?



profunctional
16 Jul 2010, 9:31 AM
I have a formpanel with a textfield. How do I attach an onclick handler to the textfield? Basically, when the textfield is clicked, I need to fire an event.

Thanks.

evant
18 Jul 2010, 9:29 PM
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function(){

var formBase = {
scroll: 'vertical',

items: [{
xtype: 'textfield',
name: 'rank',
label: 'My Field',
listeners: {
afterrender: function(c){
c.fieldEl.on('click', function(){
c.setValue('tapped');
});
}
}
}]
};

if (Ext.platform.isAndroidOS) {
formBase.items.unshift({
xtype: 'component',
styleHtmlContent: true,
html: '<span style="color: red">Forms on Android are currently under development. We are working hard to improve this in upcoming releases.</span>'
});
}

if (Ext.platform.isPhone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480
});
}

var form = new Ext.form.FormPanel(formBase);
form.show();
}
});