Ext.form.*使用技巧

设置表单控件为只读:
  1. setFieldReadOnly = function(f, bReadOnly) {
  2.     if (f instanceof Ext.form.ComboBox) {
  3.         f.setEditable(!bReadOnly);
  4.         if (bReadOnly) {
  5.             f.expandOrg = f.expand;
  6.             f.expand = function() {
  7.             };
  8.         } else {
  9.             f.expand = f.expandOrg;
  10.         }
  11.     } else {
  12.         f.getEl().dom.readOnly = bReadOnly;
  13.         if (bReadOnly)
  14.             f.getEl().addClass('x-form-readonly');
  15.         else
  16.             f.getEl().removeClass('x-form-readonly');
  17.     }
  18. };
复制代码
抑制表单提交:
  1. disableEnter = function() {
  2.     Ext.select('input').on('keypress', onEnterkey);
  3.     Ext.select('select').on('keypress', onEnterkey);
  4. }
  5. onEnterkey = function(e) {
  6.     if (e.getKey() == e.ENTER && e.target.type != null) {
  7.         if (e.target.type != 'submit' && e.target.type != 'button'
  8.             && e.target.type != 'textarea') {
  9.             e.stopEvent();
  10.         }
  11.     }
  12. }
复制代码
追加表单验证的规则:
  1. Ext.apply(Ext.form.VTypes, {
  2.     hankaku : function(v) {
  3.         var R = /^[ -~。-゚]*$/;
  4.         return R.test(v)
  5.     },
  6.     hankakuText : '只允许半角。',
  7.     hankakuMask : /[ -~。-゚]/i
  8. });
复制代码
使用Ext.Element的mask方法,把fieldset的一部分做控件为不可输入。
  1. var fieldset = Ext.get('fieldset');
  2. fieldset.on('keydown', function(e) {
  3.     e.stopEvent();
  4. });
  5. fieldset.mask();
  6. // 解除
  7. fieldset.unmask();
  8. fieldset.un('keydown', function(e) {
  9.     e.stopEvent();
  10. });
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值