profile
viewpoint

Ask questionsAppend decimal separator and places to the input when the user writes a number and there's no number present there.

I'm trying to create the autonumeric textbox, so that the decimal separator and the decimal places are appended whenever the user writes a number in the input and it's empty.

Current behavior

Decimal separator and decimal places are not appended when the user first writes a number in the textbox.

Expected behavior

Decimal separator and decimal places are appended to the user's input.

Steps to reproduce the problem

  1. Use autoNumeric version 4.1.0
  2. I instantiated the AutoNumeric textbox with the following options:
let autoNumericOptions = [
    'commaDecimalCharDotSeparator',
    {
        decimalPlaces: 2,
        decimalPlacesShownOnFocus: 2,
        formulaMode: true
    }
];
new AutoNumeric($el, autoNumericOptions);
  1. Decimal separator and decimal places are appended to the user's input.

Link to live example (ie. Codepen)

https://codepen.io/dantronik-markus/pen/YzwJgVW

tbh, I assumed that decimalPlacesShownOnFocus would take care of it, however, it seemingly does not. Also, if there's anything in the documentation regarding this issue and I missed it, I'm sorry.

autoNumeric/autoNumeric

Answer questions AlexandreBonneau

The decimal character and the decimal places (2 by default) are appended on blur. This behavior is being used to prevent messing with the user input ; we do not want to surprise the user by drastically changing the input value (by adding 3 characters on his first input).

This is why we display by default the currency characters on hover/focus for instance.

What would be your use case for this behavior?

useful!

Related questions

Destroy multiple autonumeric hot 1
The selector did not select any valid DOM element. Please check on which element you called AutoNumeric. hot 1
On initialization, `allowDecimalPadding` option `'floats'` does not hide the decimal zeroes if set in the html attribute hot 1
Need option to indicate seed value is already localized hot 1
ajax double initialize hot 1
The value [] being set falls outside of the minimumValue [] and maximumValue [] range set for this element hot 1
`digitGroupSeparator` do not recognize the `' '` string hot 1
The value [] being set falls outside of the minimumValue [] and maximumValue [] range set for this element hot 1
Admit locales (es-ES, en-GB, etc.) to format the numbers hot 1
Setting `unformatOnSubmit` to `true` does not unformat the element on the form' `submit` event hot 1
Input value will undo on focusout when using only Ctrl+Backspace hot 1
'formulaMode: true' - not working hot 1
source:https://uonfu.com/
Github User Rank List