How to not lose input value when we get focus on it? #10733
Unanswered
KindSpidey
asked this question in
Help/Questions
Replies: 2 comments
-
Here is an NPM module for the codes that you were looking for :) Have a look |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can also have a look at how it is done and apply it to your app! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, guys! I am creating a page where user can set their access code for entering the app. I didnt find inputs specially for codes, so I decided to create my own custom input which is just a group of 4 inputs for each digit.
Each input has this HTML code:
This refs and method in which I move focus to the new input after we typed in a number into current one:
This code works correctly and it does what it should: when a digit is typed in, focus moves to next input. But now I decided to create also a function that allows user to delete/backspace his code/letter and if backspace/delete pressed on an empty input form, our focus goes to previous one, meaning that user want to edit a previous one now.
For these purposes I wrote 2 functions:
handleBackspace works fine too, as the focusPreviousField by the way. The problem starts when we call command
document.getElementById('digit3').focus();
I have no idea why, but when we trying to focus on the input which already has value inside, old value just disappears and we are inside empty input form. How to fix that and what causes this problem?Beta Was this translation helpful? Give feedback.
All reactions