cesarrew / ng2-currency-mask

A very simple currency mask directive that allows using a number attribute with the ngModel.
MIT License
235 stars 117 forks source link

On clearing field the input defaults to '0' #30

Closed FaraKahir2 closed 6 years ago

FaraKahir2 commented 7 years ago

On clearing an input field I would like the text to be blank rather than default to '0' Ideally, I would like to be able to configure this in the options settings. At the moment even when I delete the 0, if still says zero.

ebosantos commented 7 years ago

it'd be a great improvement.

jans-y commented 7 years ago

In the /src/input.service.js on line 20 add to the top of the function:

InputService.prototype.applyMask = function (isNumber, rawValue) { if(rawValue == '') { // <-- checking if you cleared it. return ''; // <-- this is returning empty string to have it blank } else { ......original code ..... } }

stieler-it commented 7 years ago

The fix by @jans-y does not seem to work in all cases. I can only clear the value by leaving the field, focusing it again and then pressing space. It does not even work with backspace / delete. (Tested in Chrome)

ghost commented 6 years ago

Setting an empty value to default 0 is a critical issue since the value 0 has a semantical meaning. The empty field should set the model to NULL (as usual)!

How to empty the input field if it's a non-required field?? Need an urgent fix otherwise the component is not useable without hacking the code. :(

cesarrew commented 6 years ago

I will prioritize this issue and do it asap.

cesarrew commented 6 years ago

Fixed in version 4.4.0.

debuggerpk commented 6 years ago

Hey @cesarrew. We should probably have an option, allowBlank. The way before 649cd8734 was how we intended we were using it. makes sense?

//ysf

AndrewEckart commented 6 years ago

@cesarrew would it be possible to add an option for the value the field should be reset to if it is cleared? The default could remain null, but it'd be nice to be able to override it with 0 or another value.