PDA

View Full Version : Possible subtle misbehaviour in Field class



mabello
9 Oct 2009, 4:09 AM
Hi there,
I just want to discuss the possibility to have a misbehaviour due to this small piece of code taken from the Field class, in particular due to {buffer:10}



initEvents : function(){
this.el.on(Ext.isIE || Ext.isSafari3 ? "keydown" : "keypress", this.fireKey, this);
this.el.on("focus", this.onFocus, this);

// fix weird FF/Win editor issue when changing OS window focus
var o = this.inEditor && Ext.isWindows && Ext.isGecko ? {buffer:10} : null;
this.el.on("blur", this.onBlur, this, o);//It will fire the change event of the combo for example
},

I have already discuss the problem months ago, I think with Condor in which this code will bring to a bug in the following situation:

1. The change event of a combobox is used to save a value of the combo in an underlying JSON object.
2. I have a From Panel with a Save button in a Toolbar in which I specified a handler to send the underlying JSON object to the server
3. I change the value of the combobox but it keeps the focus so that the change event does not fire yet.
4. I press "too" quickly the Save button, the change event will be fired after the handler attached to the Save button is executed because the 10ms of buffering, so the change event will be missed, ergo problem in your code since the underlying JSON won't have the selected value of the combobox.

Not sure this is clear, but it can bring to a very subtle bug in that case

Cheers

MaximGB
9 Oct 2009, 6:10 AM
Knowing the roots of problem you can delay your Save button click handler by, say 100 ms.

mabello
9 Oct 2009, 6:25 AM
Thanks MaximGB,
You are definitely right of course (I actually did that and 50ms is enough, but it doesn't feel too good), the point was more to understand if there is a better workaround than that for FF/Win editor issue.
Cheers

mystix
9 Oct 2009, 8:20 AM
my 2 cents:

to be completely foolproof, both the creation of the JSON object to be sent to the server, and the triggering of the transmission, should be handled by the Save button. i.e. when the Save button is clicked, it should collect the values to be consolidated into a JSON object, and then trigger the process of sending it across the wire.


p.s. unfortunately for us web devs, in quite a few circumstances, a split-second delay is the only known way to deal with certain browser intricacies like the M$-Win window focus issue that 10ms buffer attempts to correct.

mabello
10 Oct 2009, 2:48 AM
Hi mystix,
Thanks for your idea.
Yes, It's a good alternative but if you can just use databinding, you end up writing less code and a more robust one in my opinion. The scenario in my mind is different, your object is created server-side (as a Data Transfer Object) and client-side you just bind your controls to properties.
If your view use late rendering, for example using Tabs with deferred rendering, then you have to use the activate and deactivate events and ask to each "binded" component contained in your tab to update itself to dislay the property and save its value to the underlying object, as you describe in your model.
Thanks again for your help

mystix
10 Oct 2009, 8:00 AM
If your view use late rendering, for example using Tabs with deferred rendering, then you have to use the activate and deactivate events and ask to each "binded" component contained in your tab to update itself to dislay the property and save its value to the underlying object, as you describe in your model.
Thanks again for your help

yep, that's my scenario exactly. :)