cesarrew / ng2-currency-mask

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

Minimum and maximum values #96

Closed pripatelUK closed 6 years ago

pripatelUK commented 6 years ago

Long time user of this mask, previously i had been using the minlength and maxlength workaround to set the a range of numbers that can be inserted. I think with the introduction of Angular 4 and 5 the mask stopped performing to the minlength attribute, (maxlength currently still works).

This means that I can no longer set a minimum value for the input. As a workaround I have altered the clearMask function in InputService to define the minimum value as zero (instead of null).

        if (rawValue == null || rawValue == "") {
            return 0;
        }

Though the DOM still removes the entire field including the placeholder. I fixed that issue by amending the applyMask function in InputService

        if (!onlyNumbers) {
            return  prefix + "0" + decimal + decimalPart + suffix;
        }

It seems users of this package have been looking for a method to implement a range of values to particular fields, I.E Issue 90 I propose maybe it could be useful to add a minimum and maximum value to the options object.

cesarrew commented 6 years ago

Minimum and maximum values validation are now available in version 5.3.0.