Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

How to pass the press key to Keydown event

I need to implement the following in my App page:

pre
$("#StreamUrl").keydown(function (e) {
if (e.keyCode == 32) {
$(this).val($(this).val() + "-"); // append '-' to input
return false; // return false to prevent space from being added
}
}).change(function (e) {
$(this).val(function (i, v) { return v.replace(/ /g, "-"); });
});
/pre

Basically I want to prevent the user form keying in space character.
I found that it can be down on keydown event. The above script taken from here (http://stackoverflow.com/questions/38...) is plain jQuery. In Appery, I have the keydown event, but I do not know how to pass 'e' parameter to it.

Please advise.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

How to pass the press key to Keydown event

You don't have to pass a value for 'e', it is the event object and e.keycode will contain 32 if someone clicks . I am unsure, however, if this has relevance to a mobile device.

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

How to pass the press key to Keydown event

Thanks Terry, But I still do not know how to implement this in Appery.
If I do not pass 'e', get undefined for 'e.keyCode ==32'

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

How to pass the press key to Keydown event

You can check that e exists by a test in your javascript:

if (e) {
console.log('keydown event: ',e);
} else {
console.log('event variable does not exist');
}

Assuming e does exist you may be able the check the object contents using the console.

It appears that the e.keyCode is not available on all browsers, it is basically a microsoft thing, you may need to look for e.which also. check out this page:

http://stackoverflow.com/questions/76...

I imagine the js or jquery would probably go into the load or pageshow events of your appery page

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to pass the press key to Keydown event

Hello,

Please use an object "event" to get all information about the event in Appery.io default events, e.g.:

preconsole.log(event.keyCode);/pre

on the keyUp event

Hawk
Posts: 0
Joined: Mon Aug 04, 2014 11:23 am

How to pass the press key to Keydown event

Thanks Sergiy

Return to “Issues”