PDA

View Full Version : [2.0a1][CLOSED] ESC 2x clears form on IE



mikegiddens
9 Oct 2007, 1:33 PM
Problem: If you press ESC twice while in a form i.e. text box the whole Ext.Form clears on the second ESC.

Browsers:
IE7: BUG
FF2: OK

Tested EXT Demo and my forms and saw the same effect.

http://extjs.com/deploy/ext-2.0-alpha1/examples/form/dynamic.html

-Mike

jack.slocum
9 Oct 2007, 4:04 PM
We aren't doing anything with ESC in the forms, it must be an IE "feature".

To test this out, I went to yahoo.com in IE7. I clicked on "Sign Up". I hit ESC twice and the form cleared.

mikegiddens
9 Oct 2007, 4:43 PM
This seems to be the only relevent article on a possible workaround. Didn't test the idea but going to look to seeing what can be done. This is causing a problem when my data is cleared and there is no way to get it back.

http://www.derkeiler.com/Mailing-Lists/Full-Disclosure/2006-06/msg00144.html

Do you plan to try and implement a ESC FORM workaround if it is possible?

-Mike

jack.slocum
9 Oct 2007, 8:14 PM
If it's the default browser behavior, we probably don't want to auto remove it. Some users may actually like it (??). Have you tried adding a key listener to the form and calling preventDefault?

mikegiddens
9 Oct 2007, 9:40 PM
new Ext.form.TextField({
fieldLabel: 'Test',
name: 'test',
listeners: {
'specialKey': this.dontResetForm
}
})

...

dontResetForm: function(field,e) {
if (e.getKey() == e.ESC) {
e.preventDefault();
}
}



I was able to add this listener to individual fields and it seems to prevent the issue but was not sure how to get a global listener to work for the form in general.

I still think this is a BAD side effect and think there should be some option to disable this ESC command via Ext config. I have a feeling now that people know this exists 90/10 will not want there form to magically erase all the data by default.

-Mike

jack.slocum
9 Oct 2007, 9:53 PM
You could use the keys config:


keys: {key: 27, fn: function(k, e){ e.preventDefault(); }}

Or even better, define this somewhere:


Ext.form.preventEscKey = {key: 27, fn: function(k, e){ e.preventDefault(); }};

Then pass it in your form config:


keys: Ext.form.preventEscKey

mikegiddens
9 Oct 2007, 10:10 PM
AHHHH you beat me to the answer. :)

I just found the "Key" feature and worked out the same solution. I have tested the below code and it works to solve the IE ESC reset problem.


keys: { key: 27, fn: function(field,e) {e.preventDefault(); },

Note this is added to the Ext.FormPanel config options

I guess this is solved even though this is a manual solution. Please let us know if you decided to add some option to the forms config.

Thanks a bunch. Learned something new today.

-Mike

jack.slocum
10 Oct 2007, 9:57 AM
You can also do it global on all forms.


if(Ext.isIE){
Ext.form.FormPanel.prototype.keys = {key: 27, fn: function(k, e){ e.preventDefault(); }};
}

However this prevents adding other keys since those configs will override the prototyped ones.