PDA

View Full Version : event handling order for TextField



TaterSalad
16 Oct 2008, 8:28 AM
It seems if I create a TextField and I do field.getValue() on keydown, keyup, or keypress, I don't get the value of that just-added key. Instead I get whatever was in the field just prior to the keypress. If I add a 10ms delay I get the right value, though.

Since this seems a fairly common use case for these events, it would be nice if the execution of the two processes (adding the key to the value, and firing the event) were re-ordered. Or if they are already in order and it's a race condition, adding a lock or follow up check to ensure the expected value is returned.

For keydown I think either way is fine.
But for keyup and keypress, the value is visible and the user interaction is done, so getValue() should return the full shown value.

Thanks

Animal
16 Oct 2008, 10:13 AM
That's the browser. The browser fires the event when it fires it. It's so that you can cancel the event and prevent input.

TaterSalad
17 Oct 2008, 8:11 AM
One goal for our organization by using Ext is to minimize or eliminate cross browser if/else special casing.

When you say Ext is a "cross-browser JavaScript library" that "supports all major web browsers" is your intention to make Ext widgets in these browsers behave and appear the same, or do you just mean Ext works on all browsers without throwing exceptions, but they may behave differently in each environment?

jack.slocum
18 Oct 2008, 1:47 PM
This is the behavior of all browsers. Key handling fires in a particular order allowing you to do different things at different times (e.g. stop a key from ever hitting the field). The only way to ensure the value has updated is by using a delay which is how I would do it as well. There is no key level event in HTML that is for "key entered and the field is updated".