extjs 表单输入框失去焦点后访问后台验证事件

extjs | 2019-09-13 10:02:39


 extjs 表单输入框失去焦点后台验证检查是否存在重复的案例代码如下:

xtype:"form",
items:[{
xtype:'textfield',
name: 'name',
fieldLabel:'名称',
allowBlank: false,//是否允许为空
msgTarget : 'side',//验证错误显示方式
labelWidth:60,//标签宽度
labelAlign:"right",//标签对齐方式
checkChangeEvents:["blur"],//控制失去焦点时才验证
validator:function(value){
        var classField=Ext.ComponentQuery.query("basedata-addform textfield[name='type']")[0];//选择器找到类别,因为我判断检查某一类别下是否重复
        var classValue=classField.getValue();
        
        if(classValue){
                if(value){
                        var validateResult=true;
                        Ext.Ajax.request({
                                url:contextPath + '/basedata/checkDataNameRepeat',
                                params: {type:classValue,name:value},
                                async:false,//一定要设置同步
                                success: function(response){
                                        var data=Ext.decode(response.responseText);
                                        validateResult= data.success;
                                }
                        });
                        return validateResult;//返回检查结果
                }else{
                        return false;
                }
        }else{
                classField.validate();
                return false;
        }
}
}]


后台返回数据格式:

{"data":null,"errorMessage":"已经重复","success":false,"total":0,"fail":true}


登录后即可回复 登录 | 注册
    
关注编程学问公众号