question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On initialization, `allowDecimalPadding` option `'floats'` does not hide the decimal zeroes if set in the html attribute

See original GitHub issue

Current behavior

If have this options to my “decimal” inputs:

decimal_autonumeric_options = {
    modifyValueOnWheel: false,
    digitGroupSeparator: '.',
    decimalCharacter: ',',
    decimalPlaces: 2,
    maximumValue: 999999999999,
    unformatOnSubmit: true,
    allowDecimalPadding: 'floats',
    decimalCharacterAlternative: ".",
    formatOnPageLoad: true,
  }

I initialize the inputs with:

AutoNumeric.multiple "input.decimal", decimal_autonumeric_options

Expected behavior

When raw value of a input is, for example: 150

It should show on input “150” on initalization and first show of the page.

But, actually shows “150,0

Afer a mouseover/mouseenter event, the input becomes “150”, so, Autonumeric removes the zero decimal digit after mouseenter, exactly like we wants due option allowDecimalPadding: ‘floats’, but it behaves wrong on init.

What a did to fix this behavior was, adding a “fake” mouseenter event after initialization to format correctly:

// Fixer for decimal digits after initialization
$.each($('input.decimal'), function(name, element) {
  var autonumeric_instance;
  autonumeric_instance = AutoNumeric.getAutoNumericElement(element);
  if (autonumeric_instance) {
    return autonumeric_instance._onFocusInAndMouseEnterFunc(new Event('mouseenter'));
  }
});

All the inputs will show correctly after that fixer.

¿Is this a bug or I have something wrong on my options?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexandreBonneaucommented, Oct 8, 2019

We assumed when the decimal part value was equal to zero, that there was no need to bother with it, and it got concatenated while still having one or more '0' as a string. The assumption is now removed, and the fix is in v4.5.8 !

1reaction
AlexandreBonneaucommented, Sep 27, 2019

@camilova I tested under Firefox and Chromium, and couldn’t reproduce the bug using the latest 4.5.7 version.

Could you please provide a reproducible test case ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle floats and decimal separators with html5 input ...
I think what's missing in the answers above is the need to specify a different value for the step attribute, which has a...
Read more >
WRITE - format_options - ABAP Keyword Documentation
In data type f, the mantissa is adjusted to this exponent by moving the decimal point and padding with zeroes. If exp contains...
Read more >
autonumeric - npm
allowDecimalPadding, Allow padding the decimal places with zeros. If set to 'floats' , padding is only done when there are some decimals. true....
Read more >
Floating point numbers - Manual - PHP
If the string is numeric or leading numeric then it will resolve to the corresponding float value, otherwise it is converted to zero...
Read more >
https://raw.githubusercontent.com/BobKnothe/autoNu...
4.1.0-beta.22 + Fix issue #525 The `input` event is not fired on mouse wheel ... `allowDecimalPadding` set to `'floats'` when `decimalPlaces` is different ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found