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.

Problem with currencySymbol containing dollar sign character

See original GitHub issue

Current behavior

When the currencySymbol contains a dollar sign a problem happens with the caret position. When you try to edit a value already formatted the caret always go to the end of the input.

Expected behavior

The caret should stay on the same place.

Steps to reproduce the problem

  1. Tested on autoNumeric version <v4.5.9>
  2. In the browser <Chrome> version <74>
  3. On the <Linux> operating system
  4. Then instantiate the autoNumeric object with the following options:
new AutoNumeric(domElement, { currencySymbol: 'R$ ' });

or

new AutoNumeric(domElement).brazilian();

or

new AutoNumeric(domElement, { currencySymbol: '$ ' });
  1. Input some value. Click outside the input. Click back inside the input, put the caret before the decimal character. Type some number. ERROR! The caret went to the end!

Debugging

The problem is the function _formatValue.

        var leftReg;

        if (this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.suffix) {
          leftReg = new RegExp("^.*?".concat(leftAr.join('.*?')));
        } else {
          // prefix is assumed
          leftReg = new RegExp("^.*".concat(this.settings.currencySymbol, ".*").concat(leftAr.join('.*?'))); // Fixes issue #647 when using a currency that has some characters in it that matches the value we just entered (ie. numbers in the currency)
        } // Search cursor position in formatted value

        var newLeft = value.match(leftReg);

When the currencySymbol has a dollar sign the value.match does not work. The dollar sign on the leftReg expression should be escaped.

Link to live example

I’ve tested on the autonumeric codepen example… Just change .french() to .brazilian() and that is it!

Thanks!!!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
VEniscommented, Oct 2, 2020

As a quick workaround you can use another unicode dollar sign symbol like https://www.compart.com/en/unicode/U+FF04 as a currency symbol

0reactions
Blackbaud-TrevorBurchcommented, Oct 26, 2021

@AlexandreBonneau - I see that a fix #684, which this appears to be a duplicate of, this was merged into the codebase on July 7. However, it does not seem that a release has been cut with this fix. Would you happen to have an ETA for when a release might happen for this fix? Thanks for any info! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with Currency Symbol - Apple Community
I prefer showing it as "$". But if I change the Currency to US Dollar ($), the symbol will become "US$".
Read more >
how to fix dollar symbols ($) that change to (¤) in my jsp page?
Missing character-encoding declaration. You likely have neglected to specify a character encoding for your JSP page.
Read more >
Developers - Problem with currencySymbol containing dollar sign ...
Problem with currencySymbol containing dollar sign character. ... When the currencySymbol contains a dollar sign a problem happens with the caret position.
Read more >
Add or remove a currency symbol in a text box or expression box
In Microsoft Office InfoPath, you can add data formatting to text box, expression box, and date picker controls on your form template to...
Read more >
Suppress currency dollar sign after first use - SAP Community
My preivous post on this problem gave me the following working solution for ... Remove the currency symbol suppression formula for the currency...
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