Programmatic value change on input field is ignored by Ctrl-Z and can't be "undo"-ne
Asked Answered
O

0

7

When I have an input field with a certain value in it, and some JavaScript changes its value, I used to be able to click into the field and hit Ctrl-Z in order to get the old value back.

It seems it doesn't work anymore, is that a recent update of the browsers? I am doing something wrong? Is there a way to make it work again?

setTimeout(function () {
  document.getElementById("name").value = ""
}, 2000);
<input type="text" id="name" value="Sylvain" />
Okhotsk answered 13/9, 2017 at 17:38 Comment(6)
I found that Chromium correctly undoes the change. At least for restoring past user input actionsPreempt
@Preempt I think you misread my question (unless I misread your comment), I'm only talking about "programmatic" changes to the text field, not user input actions.Okhotsk
What I meant was: Input -> some change (likereplace) -> More input. Only Chrome correctly handles Ctrl-Z. I found that the Mozilla and MS browsers do not go back past the change. I realize that is not quite exactly your case, and also have no solution to offer. Hence the comment and not an answer.Preempt
Oh ok I get it, thanks for the input (haha) then.Okhotsk
Answered here: HTML Input - Undo history lost when setting input value programmaticallyCrematorium
Does this answer your question? Is it possible to edit a text input with javascript and add to the Undo stack?Musil

© 2022 - 2024 — McMap. All rights reserved.