Extjs表單輸入框非同步校正的外掛程式實現

來源:互聯網
上載者:User

標籤:資料   表單   .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表單輸入框非同步校正的外掛程式實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.