PDA

View Full Version : EventObject.Enter and Button Click



prabhat2486
27 Jan 2011, 1:19 AM
Dear All,

I have designed a Window which contains two button OK and Cancel. I have added key i.e. Ext.EventObject.ENTER for OK button function. This means same handler function i have linked in Key section and button config section section. When i press Enter button my form gets submittes because OK button function is linked with Enter key press. But when i tab to OK button and then press Enter button from key board, my handler function gets called twice. Once for Enter button pressed and second for OK button because i pressed Enter button when my tab was present at OK button.

But it should be called once.

Below are some code excerpts:

openDayWisePwdExpiryFormWin : function(btn){
this.resetPwdFormWin = new Ext.Window({
title:'Change Login Password',
width: 420,
animateTarget:'workstation-tab-panel',
animCollapse:true,
autoHeight: true,
modal:true,
closable:false,
keys:[{
key: Ext.EventObject.ENTER,
scope: this,
handler: this.onResetExpiryPwdFormDlgClickOk
},{
key: Ext.EventObject.ESC,
handler: function(){
this.resetPwdFormWin.close();
},
scope: this
}],
buttons: [{
text: 'Change Password',
iconCls:'icon-disk',
handler: this.onResetExpiryPwdFormDlgClickOk,
scope: this
},{
text:'Continue Anyway',
tooltip:'Continue Anyway',
iconCls:'icon-accept',
handler: function(){
this.resetPwdFormWin.close();
},
scope: this
}],
items:[{
xtype: 'resetpwdexpiredaysform'
}]
});
this.resetPwdFormWin.show();
return;
},

onResetPwdFormDlgClickOk: function(btn, evt){

var winform = this.resetPwdFormWin.findByType('resetpasswordform')[0].getForm();
if (!winform.isValid()) {
Ext.Msg.alert('Action Status', 'Please enter the value in mandatory field(s).');
return;
}

Ext.Ajax.request({
url: '/PersonCommand?actionMode=CHANGEPASSWORD',
method: 'POST',
params: {'password':winform.findField('password').getValue(),'confirmPassword':winform.findField('confirmPassword').getValue()},
scope: this,
success: function(responseObject) {
this.resetPwdFormWin.close();
Ext.Notifier.msg('Reset Login Password', "Login password has been updated successfully.");
},
failure: function(responseObject) {

var resobject = Ext.util.JSON.decode(responseObject.responseText);
var level = 0;
try {
level = resobject.level;
} catch(err){}
if (level == 601) {
Ext.MessageBox.alert('Password Error', resobject.errorMsg);
return;
}
if (level == 602) {
Ext.MessageBox.alert('Password Error', resobject.errorMsg);
return;
}
if (level == 603) {
Ext.MessageBox.alert('Password Error', resobject.errorMsg);
return;
}
Ext.MessageBox.alert('Information', 'Problem occurred while processing your request.');
}
});
}

Please suggest me how should i achieve this.

Thanks in advance,

Regards,
Prabhat Kumar

30 Jan 2011, 6:01 PM
Prabhat Please post code that is wrapped in code tags in the future.

30 Jan 2011, 6:03 PM
to quickly fix this, set a local reference like this.isCommunication = true *before* your ajax request, and upon success/failure of that async request, clear that flag.