PDA

View Full Version : Special key event calling a function? [SOLVED]



Sloger
14 May 2010, 1:24 PM
Hello,
I realize that my question may be too primitive, but I'm new in Ext in general...

Could you please help me to create a special key event that would call a function.
I have created a NumberField and need to call a function when user enters amount and hits enter.
I have created a listener but stacked with the specialkey function. I get an error all the time!
Could you please see what's wrong with the code and give me the correct sentence:


objCustomAmountField = new Ext.form.NumberField({
allowBlank: false,
allowNegative: false,
fieldLabel: 'Enter amount: ',
id: 'customAmount',
name: 'customAmount',
listeners:{
specialkey:function(customAmount,e){
if (e.getKey() == e.ENTER) {
confirmationMsg();
}
}
}
});Thank you!

CrazyEnigma
14 May 2010, 2:16 PM
You could try KeyMap.

But what is the error? I don't see any problems, because I use the same listener for a login form.

giri_sri_d
14 May 2010, 5:23 PM
var mywin = new Ext.Window({width:100, height:100});
objCustomAmountField = new Ext.form.NumberField({
allowBlank: false,
allowNegative: false,
fieldLabel: 'Enter amount: ',
id: 'customAmount',
name: 'customAmount',
listeners:{
specialkey:function(customAmount,e){
if (e.getKey() == e.ENTER) {
alert("In here");
}
}
}
});
mywin.add(objCustomAmountField);
mywin.show();

Tried the above code in FF and there is no error encountered. I guess there is some issue either in your "confirmationMsg();" function or browser related.

Sloger
17 May 2010, 10:27 AM
I think the problem is the other (blur) function in the listeners
The actual code was:

objCustomAmountField = new Ext.form.NumberField({
allowBlank: false,
allowNegative: false,
fieldLabel: 'Enter amount: ',
id: 'customAmount',
name: 'customAmount',
listeners:{
blur: function(customAmount){
$x('P141_CUSTOM_AMOUNT').value = customAmount.getValue();
}
specialkey:function(customAmount,e){
if (e.getKey() == e.ENTER) {
confirmationMsg();
}
}
}
});

but the error I am getting:
missing } after property list
specialkey:function(customAmount,e){\n

CrazyEnigma
17 May 2010, 10:36 AM
What do you mean that the problem is the blur listener? Do you mean you solved it?

Ahhh, nevermind. Whenever you encounter a "}" error, it usually means you are missing a "," somewhere. And...

You are missing a comma after the blur listener declaration.

And sometimes you just need an extra set of eyeballs to see that is the case.

Sloger
17 May 2010, 11:36 AM
That's it! The comma was a problem! I had to post the entire code in the first place... Because when you wrote that you see no problem, and giri_sri-d wrote that the code works, I have commented the blur event and it really worked. That's when I suspended that the problem is not where I'm looking... My problem is not an extra set of eyeballs but the lack of experience...))

Thank you for your help!!

CrazyEnigma
17 May 2010, 12:23 PM
There's no problems with having an extra set of eyeballs to find your problems. I get myopic sometimes myself.

If it is SOLVED, then I suggest editing your initial post title and appending [SOLVED]

Cheers.

Sloger
17 May 2010, 12:35 PM
What is a KeyMap that you mentioned?
Could you give a link, please?

Thank you again...

CrazyEnigma
18 May 2010, 3:46 AM
KeyMap is used to attach shortcut keys to your application. The API should have it.