View Full Version : keypress/keyup event with old and new textfield value

13 Mar 2014, 11:58 AM
Does anyone know how to obtain in keypress / keyup event of a textfield the old value and the new value. I mean the value of the textfield before pressing the key and the value after keyup ??

I need to construct and event listener that fires only when the user changes the textfield value, not when it is programatically changed.

I have read some workaround, to store in a property of the textfield the old value and then ask for the new value in keypress event to compare. But i haven't any example of this solution.


13 Mar 2014, 10:06 PM

Not sure...if you require this...just check it

Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false, // requires a non-empty value
listeners: {
change: function(comp, newValue, oldValue, eOpts) {
if (newValue !== '' && newValue !== oldValue) {
}, {
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email' // requires value to be a valid email address format

Md Naveed

14 Mar 2014, 12:19 AM
Naveed, i cannot use change event because is fired when i programatically setValue in some fields. I need to isolate the firing of an event JUST when user types some new value in the field


14 Mar 2014, 4:24 AM
You could save off the value in keyPress or keyDown and then read it again in keyUp. You could also use the char code off the event to try to work out what the new value will be in keyPress or keyDown.

This is an example of saving off value in keyDown / keyPress.