Looking to modify an input value without using the element.value
property. The goal is to edit the value without replacing the entire string in the element.
For instance, we want to remove the first character from the input field:
this.value.substring(1)
returns a new value instead of directly modifying the string, so it doesn't change the original value there.
We attempted to treat the string as an array with methods like this.value.shift()
or
Array.prototype.shift.apply(this.value, [])
, but these approaches didn't work, which was expected.
The main objective is to alter the input value without affecting the caret's position. While setting the caret position manually after changing the input value is an option, it leads to its own set of issues that we are trying to avoid completely.
To summarize, we want to be able to:
- Modify the value (removing or inserting a character at any given position) in a text input without directly setting the element.value.
- Make changes without setting or adjusting the caret position.
The question remains: Is this even achievable?