標籤:資料 表單 .com response lan 應用 sage event ldl
一、效果
特點:1、非同步後台校正不會對使用者操作產生阻塞感;2、可在使用者停止輸入後自動校正,避免頻繁進行無謂的後台校正;3、以外掛程式方式實現,方便使用;二、外掛程式源碼如下:/*** Created by jiawenjun on 2016/10/19.*/
Ext.define(‘Ux.plugins.FieldAjaxVerify‘,{
extend: ‘Ext.AbstractPlugin‘,
alias: ‘plugin.fieldajaxverify‘,
buffer:500,
url:‘‘,
timeout:1000,
connectionFailure:‘伺服器串連失敗‘,
init:function(field){
var me=this;
var params=me.params;
field.enableKeyEvents=true;
field.on(‘keyup‘,Ext.Function.createBuffered(function(field,e){
var value=field.getValue();
if(Ext.isEmpty(value)){
return;
}
var params=field.up(‘form‘).getValues();
if(Ext.isFunction(me.getParams)){
params=me.getParams(field,value);
}
Ext.Ajax.request({
url:me.url,
method:"POST",
params:params,
timeout: me.timeout,
contentType: "application/json; charset=utf-8",
success:function(response){
var obj = Ext.JSON.decode(response.responseText);
if(obj.result["success"]===true){
field.setValidation(true);
field.validate();
}else{
field.setValidation(obj.result["message"]);
field.validate();
}
},
failure:function(response){
var result = Ext.JSON.decode(response.responseText);
field.setValidation(me.connectionFailure);
field.validate();
}
});
},me.buffer))
}
});三、應用方式{name:‘equipmentLedgerCategoryName‘,fieldLabel:‘分類名稱‘ ,allowBlank:false ,afterLabelTextTpl :‘
<span style="color:red;font-weight:bold" data-qtip="必填項">*</span>‘
,plugins:{ptype: ‘fieldajaxverify‘,url:‘/service/uniquenessCheckName‘}}可用配置項:1、buffer 毫秒數(在多少毫秒內使用者沒有輸入操作則自動向後台發送驗證請求2、timeout ajax請求逾時限制(毫秒數)3、getParams(field,value) 自訂ajax參數內容 四、後台服務提供的資料格式{ "resultCode" : 0, "result" : { "message" : "分類名稱重複", "success" : false }, "msgId" : "41c2c52c-66d4-49c5-be52-0158e71cfe2c", "success" : true}備忘:在Extjs5.1下測試通過,有其他個人化需求可參考此外掛程式進行實現,謝謝。
Extjs表單輸入框非同步校正的外掛程式實現