PDA

View Full Version : Does field have a "editing" event compare with "change"?



yAdEs
7 Apr 2012, 10:12 AM
I wanna listen user's editing event and use field's value to change something else, but in 4.1, I can only listen the "change" event which always fired by "setValue" method.
It's kind weird cause "setValue" by program should be different from user's editing event, so I have to rewrite an other "putValue" method which do not fire "change" event, and change every "setValue" method which used by my program to "putValue" to solve this problem.
Hope you guys solve it later:)

scottmartin
7 Apr 2012, 12:35 PM
I am not sure I understand your requirement. You want to change a value of another editor based on the changes of the first editor?



Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
fieldLabel: 'Name 1',
listeners: {
change: function(field,newValue,oldValue){
var fld2 = field.up('form').down('#text2').setValue(newValue);
}
}
}, {
xtype: 'textfield',
itemId: 'text2',
fieldLabel: 'Name 2'
}]
});


Please modify the above code to meet your requirements.

Regards,
Scott.

yAdEs
7 Apr 2012, 6:12 PM
scottmartin,

Right, I focus "target" field and set its propertie value(like its width) to "width" field, and when I change the value of "width" field, it automaticlly change the state of target.

I change code like this:

Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
fieldLabel: 'width',
itemId: "'width'",
listeners: {
change: function(field,newValue,oldValue){
var target = field.up('form').down('#text2').setValue(newValue);
}
}
}, {
xtype: 'textfield',
itemId: 'target',
fieldLabel: 'target',
listeners: {
focus: {
fn: me.onTargeFieldFocus,
scope: me
}
}
}],


onTargeFieldFocus: function(field, options) {
var widthfield= field.up('form').down('#width');
widthfield.setValue(target.width);
}
});

In this radical and cycling scenario, a small problem expose. "Change" event should be seperated for "setted by program" and "edited by people", but in ExtJs, all "setValue" methods fire the same "change" event. It really make us hard to use the event when we have both "setValue" and "edit" purpose.

Sorry for my bad english, hope it make you clear.:)

vietits
7 Apr 2012, 6:26 PM
One solution to skip firing 'change' event:


field.suspendCheckChange ++;
field.setValue(value);
field.suspendCheckChange--;

yAdEs
7 Apr 2012, 11:46 PM
One solution to skip firing 'change' event:


field.suspendCheckChange ++;
field.setValue(value);
field.suspendCheckChange--;


WOW, this is a good way, easy and efficiency! Thanks, vietits