Problem with currencySymbol containing dollar sign character
See original GitHub issueCurrent 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
- Tested on autoNumeric version
<v4.5.9>
- In the browser
<Chrome>
version<74>
- On the
<Linux>
operating system - Then instantiate the autoNumeric object with the following options:
new AutoNumeric(domElement, { currencySymbol: 'R$ ' });
or
new AutoNumeric(domElement).brazilian();
or
new AutoNumeric(domElement, { currencySymbol: '$ ' });
- 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:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
@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! 😄