动态自定义在后台验证输入值是否合法

以前是通过是通过指定validator实现的,比如下面“确定密码”输入框的配置项validator,但发现有个很严重的缺点,如果涉及到后台的话,前台会频繁的访问后台,很浪费资源,于是在此改进了一下。

var  PwdEditUi = Ext.extend(Ext.Window, {
    title: '修改密码',
    width: 400,
    height: 180,
    layout: 'fit',
    modal: true,
    initComponent: function () {
        this.items = [
            {
                xtype: 'form',
                ref:'form',
                baseCls: 'x-plain',
                padding: 10,
                labelWidth: 70,
                id: 'PwdForm',
                monitorValid: true,
                buttonAlign: 'center',
                defaults: { anchor: '95%' },
                items: [
                    {
                        xtype: 'textfield',
                        fieldLabel: '用 户 名',
                        name: 'Teach_username',
                        allowBlank: false,
                        blankText: '用户名不能为空!',
                        emptyText: '请输入用户名',
                        invalidText: '该用户名已存在!',
                        listeners: {
                            'blur': function () {//设置监听函数
                                PwdEditView.checkname.call(this);
                            }
                        }
                    },
                    {
                        xtype: 'textfield',
                        inputType: 'password',
                        emptyText: '请输入新密码',
                        allowBlank: false,
                        blankText: '新密码不能为空!',
                        fieldLabel: '新 密 码',
                        id: 'newPwd'
                    },
                    {
                        xtype: 'textfield',
                        inputType: 'password',
                        fieldLabel: '确认新密码',
                        id: 'affirmPwd',
                        emptyText: '请输入新密码',
                        allowBlank: false,
                        blankText: '确认新密码不能为空!',
                        invalidText: '两次密码不一致!',
                        validator: function () {
                            if (Ext.get('affirmPwd').getValue() == Ext.get('newPwd').getValue())
                                return true;
                            return false;
                        }
                    },
                    {
                        xtype:'hidden',
                        name: 'Teach_pk'
                    }
                ],
                buttons: [{
                    text: '提交',
                    formBind: true,
                    iconCls: 'submit',
                    handler: function () {
                        PwdEditView.submit();
                    }
                }, {
                    text: '退出',
                    iconCls: 'decline',
                    handler: function () {
                        PwdEditView.destroy();
                    }
                }]

            }
        ];
            PwdEditUi.superclass.initComponent.call(this);
    }
});
Ext.override(PwdEditUi, {
    //检查用户名
    checkname: function () {
        var self = this;
        var userName = self.getValue();
        Ext.Ajax.request({
            url: 'JsonPage/TeacherManage.aspx?param=checkname&rnd=' + Math.random(),
            params: { username: userName },
            success: function (response, options) {
                var result = Ext.decode(response.responseText);
                if (result.success == true) { //用户名可用
                    self.markInvalid('用户名已存在,请选择其他用户名!');
                    self.validator = null;
                } else { //用户名已存在   
                    self.markInvalid('用户名已存在,请选择其他用户名!');
                    self.validator = function () {
                        return false;
                    };
                }
            },
            failure: function () {
                msg('网络连接出错,请稍后重试!');
                self.validator = null;
            }
        });
    }
});
 PwdEditView = new PwdEditUi();
 PwdEditView.show();




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值