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.

有帮助吗?

解决方案

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.com/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);
                    }
                }
            }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top