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

[javascript]  view plain copy
  1. <span style="font-family: Arial, Verdana, sans-serif; background-color: rgb(255, 255, 255); ">以前是通过是通过指定validator实现的,比如下面“确定密码”输入框的配置项validator,但发现有个很严重的缺点,如果涉及到后台的话,前台会频繁的访问后台,很浪费资源,于是在此改进了一下。</span>  

[javascript]  view plain copy
  1. var  PwdEditUi = Ext.extend(Ext.Window, {  
  2.     title: '修改密码',  
  3.     width: 400,  
  4.     height: 180,  
  5.     layout: 'fit',  
  6.     modal: true,  
  7.     initComponent: function () {  
  8.         this.items = [  
  9.             {  
  10.                 xtype: 'form',  
  11.                 ref:'form',  
  12.                 baseCls: 'x-plain',  
  13.                 padding: 10,  
  14.                 labelWidth: 70,  
  15.                 id: 'PwdForm',  
  16.                 monitorValid: true,  
  17.                 buttonAlign: 'center',  
  18.                 defaults: { anchor: '95%' },  
  19.                 items: [  
  20.                     {  
  21.                         xtype: 'textfield',  
  22.                         fieldLabel: '用 户 名',  
  23.                         name: 'Teach_username',  
  24.                         allowBlank: false,  
  25.                         blankText: '用户名不能为空!',  
  26.                         emptyText: '请输入用户名',  
  27.                         invalidText: '该用户名已存在!',  
  28.                         listeners: {  
  29.                             'blur'function () {<span style="color: rgb(0, 153, 0); ">//设置监听函数</span>  
  30.                                 PwdEditView.checkname.call(this);  
  31.                             }  
  32.                         }  
  33.                     },  
  34.                     {  
  35.                         xtype: 'textfield',  
  36.                         inputType: 'password',  
  37.                         emptyText: '请输入新密码',  
  38.                         allowBlank: false,  
  39.                         blankText: '新密码不能为空!',  
  40.                         fieldLabel: '新 密 码',  
  41.                         id: 'newPwd'  
  42.                     },  
  43.                     {  
  44.                         xtype: 'textfield',  
  45.                         inputType: 'password',  
  46.                         fieldLabel: '确认新密码',  
  47.                         id: 'affirmPwd',  
  48.                         emptyText: '请输入新密码',  
  49.                         allowBlank: false,  
  50.                         blankText: '确认新密码不能为空!',  
  51.                         invalidText: '两次密码不一致!',  
  52.                         validator: function () {  
  53.                             if (Ext.get('affirmPwd').getValue() == Ext.get('newPwd').getValue())  
  54.                                 return true;  
  55.                             return false;  
  56.                         }  
  57.                     },  
  58.                     {  
  59.                         xtype:'hidden',  
  60.                         name: 'Teach_pk'  
  61.                     }  
  62.                 ],  
  63.                 buttons: [{  
  64.                     text: '提交',  
  65.                     formBind: true,  
  66.                     iconCls: 'submit',  
  67.                     handler: function () {  
  68.                         PwdEditView.submit();  
  69.                     }  
  70.                 }, {  
  71.                     text: '退出',  
  72.                     iconCls: 'decline',  
  73.                     handler: function () {  
  74.                         PwdEditView.destroy();  
  75.                     }  
  76.                 }]  
  77.   
  78.             }  
  79.         ];  
  80.             PwdEditUi.superclass.initComponent.call(this);  
  81.     }  
  82. });<pre name="code" class="javascript">Ext.override(PwdEditUi, {  
  83.     //检查用户名  
  84.     checkname: function () {  
  85.         var self = this;  
  86.         var userName = self.getValue();  
  87.         Ext.Ajax.request({  
  88.             url: 'JsonPage/TeacherManage.aspx?param=checkname&rnd=' + Math.random(),  
  89.             params: { username: userName },  
  90.             success: function (response, options) {  
  91.                 var result = Ext.decode(response.responseText);  
  92.                 if (result.success == true) { //用户名可用  
  93.                     self.markInvalid('用户名已存在,请选择其他用户名!');  
  94.                     self.validator = null;  
  95.                 } else { //用户名已存在     
  96.                     self.markInvalid('用户名已存在,请选择其他用户名!');  
  97.                     self.validator = function () {  
  98.                         return false;  
  99.                     };  
  100.                 }  
  101.             },  
  102.             failure: function () {  
  103.                 msg('网络连接出错,请稍后重试!');  
  104.                 self.validator = null;  
  105.             }  
  106.         });  
  107.     }  
  108. });<pre name="code" class="javascript"> PwdEditView = new PwdEditUi();  
  109.  PwdEditView.show();</pre><br>  
  110. <pre></pre>  
  111. <br>  
  112. <pre></pre>  
  113. <pre name="code" class="javascript"></pre><pre name="code" class="javascript"><p></p></pre>  
  114.   
  115. </pre>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值