It all depends on how you expect the user to do this?
The user can already backspace to the next input as that is built into most browsers bu just using SHIFT + TAB. Tab makes the cursor go to the next input and SHIFT + TAB makes it go back to the previous one. A savvy user would now this.
The backspace key deletes the character so you wouldn’t want to use that unless you wanted to delete and then auto focus in the previous input and that would require JS.
You could program the arrow keys to go back but them you’d still need to tell your user about it anyway so you may as well tell them to use Shift + Tab.
Here’s an example using the arrow keys to go backwards and forwards in those 5 inputs.
However I should refer you to the JS forum for further questions and more solid JS code than I can offer.
O k. I copied the code from the codepen and the backspace didn’t work. However I did add the div id=result and the function as in post 18. Would that have an effect on the backspace?
Thanks
The left and right arrows are working on my demo. The div# results should not interfere with anything. Did you add the data attributes to the html?
Otherwise you must have accidentally copied incorrectly or you have other code interfering with it in some way.
It’s not possible to say unless we see a demo or full working code snippets. It would be helpful if you could do as I do and post a working codepen which makes it so much easier to debug and work with
You would need to clarify the procedure that you expect to happen ? It really needs defining in detail as there are a lot of things to consider.
The backspace key already deletes the text so is not really useful for editing as you are just deleting each item. It would not be usable to stop the backspace key deleting just so you can traverse the elements because then you’d need to use another key to delete.
I suppose you could let the backspace key do it’s normal job and then move it’s focus to the previous cell but that would mean the user could not re enter the letter in the cell they just deleted!
It would seem to me that a user would delete a single letter and replace it with another rather than deleting the whole word.
If you can first define how you want the backspace key to work then you can start to make it happen.
Like if you have the word “clue” to go in the input squares, say you misspell this word, can you press the backspace key continually to the error to correct and continue typing, just as you would press the backspace key on a computer.
Does this make ANY sense???
It sort of works but you probably need to control the caret position a bit better when someone clicks into the input so that the backspace can work rather than the delete key. (I commented out the arrow key function.)
However this is out of my scope now and is really a question for the JS forum.
NOTE: There’s a bug in Firefox with the flex rule so you need to remove that I have commented out here.
Just realised its the new min-width:auto setting is now the default in Firefox and that’s why the flex-basis wasn’t being honoured. Auto means shrink wrap the content which for a replaced element like an input is wider than the 35px that was set.
Other browsers will eventually implement this as that is now the standard.
All that was needed was to set min-width:0 to over-ride the default.