Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to get value with "unmasked" when precision is 0 #123

Open
atrandafir opened this issue Apr 6, 2014 · 13 comments
Open

Problem to get value with "unmasked" when precision is 0 #123

atrandafir opened this issue Apr 6, 2014 · 13 comments
Labels
Milestone

Comments

@atrandafir
Copy link

I have configured it with precision to 0, because I dont want any decimals.

So when I type 555555 it turns into 555.555 €, but when I use "unmasked" it will bring back 555.555 instead of 555555 as it should.

@pilap82
Copy link

pilap82 commented Apr 14, 2014

same issue here

@plentz plentz added the bug label May 25, 2014
@plentz plentz added this to the 3.1 milestone May 25, 2014
@plentz
Copy link
Owner

plentz commented May 25, 2014

@atrandafir @pilap82 sorry for taking so long to reply. I will take a look at this in a few days. here's what I'm planning for maskmoney 3.1 https://github.com/plentz/jquery-maskmoney/issues?milestone=6

@ioleo
Copy link

ioleo commented Nov 5, 2014

Same issue. I've got a field with value 3. I am calling $field.maskedMoney({ precision: 0 });..

then, when I do $field.maskedMoney('unmasked')[0] it returns 0.3. Why?

@EtienneDepaulis
Copy link

Hey guys, have their been any update on this situation ?
We are suffering from the same issue :/
Cheers

@ioleo
Copy link

ioleo commented Nov 19, 2014

@EtienneDepaulis instead jqyery-maskmoney I used RobinHerbots/jquery.inputmask library (for input masking) and leongersen/wnumb for number/money formatting.

@gbass84
Copy link

gbass84 commented Nov 19, 2014

I can at least tell you what the issue is:

  1. the settings are within a closure that is bound to the element with .init, so they currently aren't accessible back to the unmask function.
  2. because of this the unmasked function uses regex "/\D/g" to split numbers by groups of non-numeric characters, and assumes that the last one is the decimal
  3. therefor if you're using precision 0, the unmask will treat your last group after a non-numeric symbol as the decimal. If the value is less than 1000, that could end up returning ""

solution:

  1. make settings available to the unmask function. This should be accomplished by writing the data attributes to field when masking
  2. in unmask function, read the data attributes and use them to run a string.replace(regex,"")

I have mocked some of this up, but the changes are pretty damn extensive.

@gbass84
Copy link

gbass84 commented Nov 21, 2014

Here's the solution I've been working on:

Move unmasked label in to init method and add an event binding to get a handle back to it. This was so that the unmask function has access to the settings object. Then I think the solution is to check for minus symbol and the index of the decimal/cents separator. Run the existing \D regex, split, and re-insert decimal symbol and -. (should it replace it with "." or with the specified separator?)

In the place of the exiting unmask method, I trigger the unmasked event on the element so that the invocation remains the same.

Any thoughts on this?

@gael-wogenstahl
Copy link

I have the same issue here.
Any plan of fixing it the way @gbass84 suggested ? I'm not good enough at javascript to handle it myself unfortunately...

@RazorCommerce
Copy link

Seeing the same issue, any work-around ideas for getting the correct value? I'm thinking of multiplying by 1,000.

@NemSavic
Copy link

@RazorCommerce

I believe I resolved this by utilizing jQuery.data() to bind the settings to the element and then reusing them to determine the decimal value. I've added a pull request for this update, #175

@nigelterry
Copy link

@NemSavic Your fix works perfectly for me. Thanks

@Audesi
Copy link

Audesi commented Sep 30, 2015

@NemSavic This is working great. Thank you!

@danieltartarottisobrosa
Copy link

I created the pull request #214 that complements the @NemSavic pull request #175, correcting tests and the build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests