Basically I have an input text (I am actually working in react, but probably the solution would be the same or very similar in plain html5-javascript) and I want that the text cursor remains on the right permanently when the users clicks on it, and that, even if the users clicks in another position of the input's content once he wrote something, the text cursor is still moved instantly to the right end.
I tried different solutions I found around but nothing seems to work.
I tried using the onFocus event passing a function like this as suggested in some questions on this site:
repositionCursorToTheRight = (e) => {
const val = e.target.value;
e.target.value = '';
e.target.value = val;
};
with the idea that resetting the input would force the text cursor to reset its position, but it doesn't happen (not in firefox at least).
I tried working with event.target.selectionStart
and event.target.selectionEnd
setting them to different values like the full lenght of the input value, 0, etc... but that seems too to have no effect at all.
Any ideas?
Edit: I'll explain better the reasons and give an example, I just want to specify this is a client business request and I cannot override it.
So I need this because I have an input form which must have 2 fixed decimals which must be always showed even if at zero. The client want a form like those of most currency converters apps in which if the user wants to write, for example, 12.35
it should see in order 0.00
(default value) -> 0.01
-> 0.12
-> 1.23
-> 12.35
. Hope it is clear now