最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs 4.1 - Disable paste event for textfields - Stack Overflow

programmeradmin6浏览0评论

I already verified there are no paste events for textfield in extjs 4.1. But i donot want that user should be able to paste into this textfield. What other options are available that user is not allowed to paste any value in the textfield. Please note that the textfield allows only numeric values, no chars/special chars or alphabets. Below is the code snippet that i have as of now.

{
                                  xtype:"textfield",    
                                  fieldLabel: 'Debit Account',
                                  name:'debitAccount',
                                  id : 'debitacct',
                                  enableKeyEvents:true,
                                  maskRe: /[0-9]/,
                                  allowBlank: false,
                                  allowNegative: false,
                                  maxLength: 9,
                                  enforceMaxLength:true,
                                  listeners : {
                                    specialkey : function(field, e) {
                                    filterBackspaceKey(e);
                                    }
                                    }
                             }

Any help is appreciated.

I already verified there are no paste events for textfield in extjs 4.1. But i donot want that user should be able to paste into this textfield. What other options are available that user is not allowed to paste any value in the textfield. Please note that the textfield allows only numeric values, no chars/special chars or alphabets. Below is the code snippet that i have as of now.

{
                                  xtype:"textfield",    
                                  fieldLabel: 'Debit Account',
                                  name:'debitAccount',
                                  id : 'debitacct',
                                  enableKeyEvents:true,
                                  maskRe: /[0-9]/,
                                  allowBlank: false,
                                  allowNegative: false,
                                  maxLength: 9,
                                  enforceMaxLength:true,
                                  listeners : {
                                    specialkey : function(field, e) {
                                    filterBackspaceKey(e);
                                    }
                                    }
                             }

Any help is appreciated.

Share Improve this question asked Dec 31, 2013 at 8:56 SKSSKS 1152 silver badges12 bronze badges 1
  • @dbrin My bad, Thank you ! I just accepted it. – SKS Commented Jan 3, 2014 at 7:10
Add a ment  | 

3 Answers 3

Reset to default 6

After i got to see the link @Sencha, the solution was easy. Code below.

{
                                  xtype:"textfield",    
                                  fieldLabel: 'Debit Account',
                                  name:'debitAccount',
                                  id : 'debitacct',
                                  enableKeyEvents:true,
                                  maskRe: /[0-9]/,
                                  allowBlank: false,
                                  allowNegative: false,
                                  maxLength: 9,
                                  enforceMaxLength:true,
                                  listeners : {
                                    specialkey : function(field, e) {
                                    filterBackspaceKey(e);
                                    },
                                    paste: {
                                        element: 'inputEl',
                                        fn: function(event, inputEl) {
                                        if(event.type == "paste"){
                                        event.preventDefault();
                                        return false;
                                        }
                                        }
                                    }
                                    }
                             }

Refer link from Sencha : http://www.sencha./forum/showthread.php?175253-Paste-event

  • On any click and keydown do this:
    • Check if old value equals to new value (change event)
    • Save new value to old value
    • If content has changed, you can diff the values and if changed part was more then one character, content has been pasted -> revert to old value

Hope that helps.

try after change your listeners to below

listeners : {
                change : function(field, newValue,oldValue) {
                    var validation=/^\d+$/;
                    if(!validation.test(newValue) && newValue!='' ) {
                        field.setValue(oldValue);
                    }
                }
            }
发布评论

评论列表(0)

  1. 暂无评论