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
3 Answers
Reset to default 6After 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);
}
}
}