I'm working on Ext 3.3.
When our form needs monitor 'enter' key event to submit form, the from will be submitted repeatedly if I click enter key more than once.
This behavior will hurt the data version controll.
I have an idea that if the form loses the focus after it reply the first time 'enter' event, the second 'enter' event won't be monitored until you focus the form again.
So, could you please share how to lose the form's focus manually or other better solution?
Thanks!
Demo below:
Code:
Ext.onReady(function() {
Ext.QuickTips.init();
var simple = new Ext.FormPanel({
labelWidth : 75,
frame : true,
title : 'Simple Form',
bodyStyle : 'padding:5px 5px 0',
width : 350,
renderTo : 'form1',
keys : [ {
key : Ext.EventObject.ENTER,
fn : Ext.createDelegate(function() {
cmp.focus(); // if the cmp is editable like textfield or combo, it can work, while label or other form can't.
console.log('hello world');
}, this)
} ],
defaults : {
width : 230
},
defaultType : 'textfield',
items : [ {
fieldLabel : 'First Name',
name : 'first'
}, {
fieldLabel : 'Last Name',
name : 'last'
}, {
fieldLabel : 'Company',
name : 'company'
} ],
buttons : [ {
text : 'Save'
}, {
text : 'Cancel'
} ]
});
var cmp = new Ext.form.Label({text:'label1'});
var simple1 = new Ext.FormPanel({
labelWidth : 75, // label settings here cascade unless overridden
frame : true,
title : 'Simple Form',
bodyStyle : 'padding:5px 5px 0',
width : 350,
renderTo : 'form2',
defaults : {
width : 230
},
items : [ cmp]
});
});