-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get pressed key onevent #91
Comments
The |
@DavidSichau if you install the dev version of shinyjs, you should now be able to use a function with an argument as the callback, and the argument will have the relevant javascript event details |
@DavidSichau it won't work with the code you tried (you probably wrote it like that because shinyjs expected an expression rather than a function). Just pass the function, without wrapping it in brackets I'd appreciate if you try the new package and let me know if it works for your purposes |
@daattali Thanks it works great. Unfortunately not on elements added by insertUI. So I will switch for them to js code. But for other cases it works. |
Hmm I don't see why it wouldn't work... as long as you're calling the
|
I made a small example app using a modal: https://gist.github.com/DavidSichau/67d20e0ac7f76acd4d1882b97e456f01 |
You have two problems with your code. First problem is that you're not including shinyjs in your UI (you MUST include a call use Second problem is what I mentioned in an above comment "it won't work with the code you tried ... Just pass the function, without wrapping it in brackets" Instead of
It should be
The first one doesn't work because you're passing an expression that's trying to access a non existent variable e, you need to pass a function instead that will only get evaluated later |
@daattali Thanks for your reply. I think the problem was that I forgot to add Now the problem is solved 👍 |
@daattali If I put the code inside a module it somehow does not work anymore: https://gist.github.com/DavidSichau/5c7bb50d4dcac68621e6b69ae9c6119d Did I again made a stupid error or is this not possible? |
That's not possible from the simple fact that what you're doing there is putting the onevent call inside UI. If you look at the documentation for If you have any bug reports you're welcome to open new issues, but I prefer that any conversation about "how do I do this/is this a bug or not?" be done on StackOverflow (that way it's easy for other people to see it in the future and other people can help me with answering questions) |
I would like to add the
onevent
listener to a form field, which should detect if the enter key is pressed.Such that I am then able to submit the form.
However I therefore need to know which key was pressed. Is there a way to gain the code of the key pressed, such that I could make a check if it is the entered key.
I tried the following code, assuming that the handler somehow gets as parameters the pressed key:
However unfortunately the pressed key is not passed and this code complains about not existent
e
. Is there another way to gain access to the pressed key?The text was updated successfully, but these errors were encountered: