定义全局检验函数
basedev.baseSite.uniqueSiteName=function(field){ if(!field){ return true; } var editBaseSiteInfoForm = Ext.getCmp(basedev.baseSite.EDIT_BASE_SITE_FORM_ID); var siteCode = editBaseSiteInfoForm.getForm().findField("siteCode").getValue(); var paramsObj = {siteCode : siteCode, siteName : field, state : editBaseSiteInfoForm.getOperatorType()}; var valid = false; Ext.Ajax.request({ url : basedev.realPath(‘uniqueCheckBySiteName.do‘), params: paramsObj, async : false, success : function(response) { var result = Ext.JSON.decode(response.responseText); if(result.success){ if(result.data == 0){ valid = true; } }else{ Ext.ux.Toast.msg(‘提示‘, result.msg); } }, failure : function(response) { Ext.ux.Toast.msg(‘提示‘,response.responseText, ‘error‘); } }); if(valid){ return true; } return ‘该门店名称已存在‘; };
控件使用blur替代 validator listeners:{ ‘blur‘:function(field){ var uniqueSiteName = basedev.baseSite.uniqueSiteName(field.rawValue); if(uniqueSiteName!=true) { field.markInvalid(uniqueSiteName); } } } /*****************提交表单时ajax校验再走一次 start*****************/ var uniqueSiteName=basedev.baseSite.uniqueSiteName(baseSiteForm.findField(‘siteName‘).getValue()); if(uniqueSiteName!=true){ baseSiteForm.findField(‘siteName‘).markInvalid(uniqueSiteName); return; }/*****************提交表单时ajax校验再走一次 end*****************/