PDA

View Full Version : [CLOSED] TriggerField and Enter key



alessandra.monica
Jul 08, 2014, 12:25 PM
I have a TriggerField with EnableKeyEvent true.
When I press a key, a filtered search is launched and below the TriggerField
a filtered TreePanel is loaded. It works fine, but I would like
to disable the ENTER key. At the moment, when I have the focus in TriggerField
and I press ENTER key, the whole page is reloaded and the whole Tree too. I simply
would like that nothing happens when I press ENTER key.

This is the piece of Code:



var filterTree = function (tf, e) {

............

if (e.getKey() == Ext.EventObject.ENTER) {
e.stopEvent();
return false;
}else {
var re = new RegExp(".*" + text + ".*", "i");

tree.filterBy(function (node) {
return re.test(node.data.text);
});
}
};

<ext:TriggerField
ID="TriggerField1"
runat="server"
EnableKeyEvents="true">
<Triggers>
<ext:FieldTrigger Icon="Clear" />
</Triggers>
<Listeners>
<KeyPress Fn="filterTree"></KeyPress>
</Listeners>
</ext:TriggerField>


Neither stopEvent, nor return false, seem to work.
The code enters in the IF part, but it reloads the page all the same.

Any idea?

Many thanks

Daniil
Jul 08, 2014, 12:45 PM
Hi @alessandra.monica,

Stopping the event in a KeyPress handler might be too late. I would try to stop it in a KeyDown or SpecialKey handler.

alessandra.monica
Jul 08, 2014, 1:01 PM
Hi Daniil,

thank you very much for you response.

With the key down I had already tried and it doesn't work..... same as key press...

As for Specialkey, could you please provide me with an example of how to use it?

Thank you!

alessandra.monica
Jul 08, 2014, 1:58 PM
I have tried with SpecialKey and it works perfectly!!

You can close the thread.

Thank you very much!