Stop user cursor before currency symbol on input

Hi guys,

Does anybody know a way of stopping a user from using the arrows keys or mouse clicking before the currency sign when using an input set to currency format? Demo below.

currency-cursor-positioning-bug

Cheers

If not possible I suppose changing the input to numbers only to keep the decimal formatting and then adding the currency prefix in separately might be the answer…

Yes, just put the currency symbol as a text to the left outside the input field

Hey @robert
Appreciate the suggestion. I have a lot of inputs using the currency option, was hoping for a javascript solution to run in the header across the site, but I think I might run with the text solution if nothing comes up. Cheers

@luke2

Javascript on page load:

// Basic cross browser addEvent
function addEvent(elem, event, fn){
if(elem.addEventListener){
elem.addEventListener(event, fn, false);
}else{
elem.attachEvent(“on” + event,
function(){ return(fn.call(elem, window.event)); });
}}
var element = document.getElementById(‘el’);

addEvent(element,‘focus’,function(){
var that = this;
setTimeout(function(){ that.selectionStart = that.selectionEnd = 10000; }, 0);
});

Give your input an ID. In this case I used ‘el’.

https://www.loom.com/share/6fa8cd5a107e4439be0eac608576fab9

Hopefully this is in the right direction?

Thanks @lantzgould this looks promising, I’ll run a test later tonight and see if I can get it running in the general <head>. Will keep you posted :+1:

1 Like

Did you get this working? I’d like to offset the caret position.

With Css seems I cannot find info. Js only.

Screenshot_20211013_120241_com.brave.browser

Edit: Just centered it…

I found this but not sure if it’s possible to use in bubble.