ExtJS Form 回车提交

/**
 * 该表单提供对各个元素回车验证并且自定切换到下一个元素功能
 */
Ext.define("Ext.ux.form.Panel",{
	extend:"Ext.form.Panel",
	isValid:function(){
		var isValid = true;
		Ext.Array.each(this.items.items,function(item,index){
			if(!item.isValid()){
				isValid = false;
				item.focus();
				return false;
			}
		});	
		return isValid;
	},
	initComponent:function(){
		var me = this;
		var specialKey = function(field,e,eOpts){
			if (e.getKey() == Ext.EventObject.ENTER) {
				var isValid = true;
				if(!field.isValid()){
					field.focus();
				}else{
					if(me.isValid()) {
						 me.getForm().updateRecord();
					 }
				}
			};
			if(field.old_specialKey){
				field.old_specialKey(field,e,eOpts);
			}
		};
		Ext.Array.each(me.items,function(item,index){
			if(!Ext.isDefined(item.enterChange) || item.enterChange){
				if(item.listeners){
					if(!item.listeners.specialKey){
						item.listeners.specialKey = specialKey;
					}else{
						item.old_specialKey = item.listeners.specialKey;
						item.listeners.specialKey = specialKey;
					}
				}else{
					item.listeners = {specialKey:specialKey};
				}	
			}
		});
		me.callParent(arguments);
	}
});

作者:cjblog
原文:http://cjblog.iteye.com/blog/1878667