You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, for UX purpose I want to remove the decimal from the input when it is equal to 0.
Like:
15 ✔️
15.0 ✔️
15.00 ✔️
15.01 ❌
So when the user focus the input, the decimal will be removed to prevent the manual triple backspace from the user to remove the two decimal and the radix.
It's a GIF click on it..
With mask.value if I give it 15, due to padFractionalZeros it will end up with 15,00.
Is there a way to force 15 without the mask?
Here's my current code that fails when:
I try to backspace immediately.
The value is < 1000 (thousand separator I guess)
It's a GIF click on it..
constelement=document.querySelector('input')constmask=Mask(element,{mask: Number,scale: 2,thousandsSeparator: ' ',padFractionalZeros: true,normalizeZeros: true,radix: ',',mapToRadix: ['.'],})element.onfocus=()=>{constvalue=element.valueif(value==0){element.select()}elseif(Number.isInteger(value)){element.value=value.toString()// Will set 15// mask.value = value.toString() // Will set 15,00element.setSelectionRange(-1,-1)}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, for UX purpose I want to remove the decimal from the input when it is equal to 0.
Like:
So when the user focus the input, the decimal will be removed to prevent the manual triple backspace from the user to remove the two decimal and the radix.
With
mask.value
if I give it15
, due to padFractionalZeros it will end up with15,00
.Is there a way to force
15
without the mask?Here's my current code that fails when:
< 1000
(thousand separator I guess)Beta Was this translation helpful? Give feedback.
All reactions