要使Ext.Editor支持回车提交,增加config
completeOnEnter: true
就可以了。
但问题来,当回车后,触发一次 this.completeEdit(); 这时我们可以用弹出提示框做一些判断,当弹出提示框时,由于焦点到了提示框上,又触发了Editor的onblur事件,Editor的onblur中又一次调用了 this.completeEdit();。所以导至 this.completeEdit();方法被执行了两次,解决办法:
重写Ext.Editor的onSpecialKey方法
Ext.override(Ext.Editor,{
onSpecialKey:function(field,e){
var key = e.getKey();
if(this.completeOnEnter && key == e.ENTER){
this.field.un('blur', this.onBlur, this); //增加的
e.stopEvent();
this.completeEdit();
this.field.on('blur', this.onBlur, this); //增加的
}else if(this.cancelOnEsc && key == e.ESC){
this.cancelEdit();
}else{
this.fireEvent('specialkey', field, e);
}
}
});