jquery-maskmoney
jquery-maskmoney copied to clipboard
Treat empty as zero
This pull request adds a new option to the library: treatEmptyAsZero.
Currently in this library, when focusing on an empty field, the masking library assumes the user intends "blank" to mean 0. I needed empty to mean "nothing" and allow the user to specify either "nothing" or 0 as the submitted value.
Here, setting treatEmptyAsZero to false allows you to delete a 0.00 masked value and allows the user to enter either a blank input or zero.
The "treatEmptyAsZero" can be set on submit form event too ?
How is this different from: https://github.com/plentz/jquery-maskmoney/pull/110? Seems to be the same thing.
Yes and No.
The treatEmptyAsZero that I was thinking is just the zero, so in this test could be like this:
test("allowZero: true - mask keeps default 0 value", function() {
var input = $("#input5").maskMoney();
input.trigger("mask");
equal(input.val(), "0.00", "0 value should be 0.00$ due to settings");
});
Nice. +1
Hey guys, thanks for looking. I needed to set this up for a personal project. Maybe I screwed up, but when I tried #110, it didn't give me the behavior I needed so I hacked it up myself and put it here in case it helps someone.
With this PR, if you set treatEmptyAsZero as false, then say you enter a value and it gets masked to $117,000. If you then select all in the field and hit backspace, it gets set to $0 and places the cursor to the right of $0. If you then hit backspace again, it will allow you to delete the $0 and have the field be considered 'nil'.
It's the best of both worlds for us and so I thought I'd share. I do, however, think I prefer @jpSimkins terminology of allowEmpty, I just didn't think of it.
Happy to rework it accordingly if you guys like the code/behavior, plan to merge it but need me to make any changes. Let me know!
Great, this is what I was looking for! +1
After 3 years, today I discovered that I need this feature in the plugin. Should be merged. +1.
@edelbalso do you can resolve this conflict?