jquery-maskmoney
jquery-maskmoney copied to clipboard
Problem to get value with "unmasked" when precision is 0
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.
same issue here
@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
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?
Hey guys, have their been any update on this situation ? We are suffering from the same issue :/ Cheers
@EtienneDepaulis instead jqyery-maskmoney I used RobinHerbots/jquery.inputmask library (for input masking) and leongersen/wnumb for number/money formatting.
I can at least tell you what the issue is:
- 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.
- 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
- 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:
- make settings available to the unmask function. This should be accomplished by writing the data attributes to field when masking
- 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.
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?
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...
Seeing the same issue, any work-around ideas for getting the correct value? I'm thinking of multiplying by 1,000.
@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
@NemSavic Your fix works perfectly for me. Thanks
@NemSavic This is working great. Thank you!
I created the pull request #214 that complements the @NemSavic pull request #175, correcting tests and the build process.