If key pressed equals delete

rp-7
newbie-question

#1

I am attempting to set the OnLoadVariable to the value of “delete” when the delete key is pressed in a form field.

I can’t seem to quite get it to work.

Am I doing something wrong, or is this not possible?

Thx!



#2

Hi ziege,

Hmm, it looks like the way that you have the case set up should work. Are you trying to set the value “delete” to be visible somewhere in your file? As it is now (from what I can see), the value of the OnLoadVariable should be correctly set to “delete”, which you can verify in your project’s preview. When you preview your project, if you click on the “x=” symbol in the sitemap, it will show you the current value of all of your variables. In this case, it should show that the value of the OnLoadVariable is equal to “delete” after you press the [Delete] key.

I attached a quick sample file that replicates your case setup, and includes a blank rectangle widget to display the variable value there in addition to the sitemap. Feel free to send over your file for me to look at if it’s still giving you trouble! :slight_smile:

Alyssa
Key Pressed equals Delete.rp (51.9 KB)


#3

Thank you, Alyssa.

Maybe this is another issue. I can’t seem to get your file to work either when I run your file. :frowning:

I’m trying to do exactly what you describe - setting a variable when the delete key is pressed. I’m using that variable elsewhere. The x= symbol indicates that the variable is not being set in either your or my prototype.

Here are two screenshots - one with 111 in the field, and one immediately after I deleted the third 1.



Could it be an issue with my configuration maybe? I’m using a Mac - not sure if that matters.


#4

Hi ziege,

Oh that’s interesting! I use an external keyboard with my Mac and the [Delete] key works both for setting up the condition in the file and executing the variable in the preview. However, I’m encountering the same issue as you when I try using the [Delete] key on the Macbook’s native keyboard. It allows you to set the condition in the file, but doesn’t set the variable in the preview–in fact it seems to act as the browser’s “Back” button if the text field isn’t selected.

Looking into it, it seems that this may potentially be a JS/Mac browser limitation, since the [Delete] key is listed as a “Special Key”. You can check out some info on that here if you’d like:

JavaScript - Detecting keystrokes

I’m going to go ahead and submit this for review to our QA team. Thanks for helping us track this down!

Alyssa


#5

It looks like you’re trying to detect when the user has deleted text in a text field? Perhaps as a workaround you try comparing the the length of the value of the text field after keydown with what it was before.


#6

Exactly - I was trying something along these lines, I ended up creating a variable and setting it in order to accomplish the goal. Good suggestion!


#7

I also am trying to ignore special characters in my form such as / and am not having any luck due to the same issue. Not sure of a workaround for that one… :frowning:


#8

The reason why the example above is not working is because wrong key is used. This varies depending upon the operating system you are using. Mac or Windows. On Windows it’s Back and not Delete. You could change the condition to satisfy both. Take a look at the example below.

Key Pressed equals Delete.rp (49.8 KB)


closed #9

unlisted #10