最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - ng2-currency-mask not allowing '-' on empty textfield - Stack Overflow

programmeradmin0浏览0评论

Angular 15.1.3 Node 18.11.9 ng2-currency-mask ^13.0.3

ng2-currency-mask allows you to format numbers with current, rate with any prefix or suffix you want to add and also custom scaling and format.

When dealing with negative values, it has a limitation, it would allow - only when you have entered any digit, it won't allow you to enter - on a empty text field.

I tried creating a directive on keydown to allow - when values is empty, still no luck.

Is there any way to allow - before entering the digits?

If not, what is the alternative I can use for the above requirements?

Angular 15.1.3 Node 18.11.9 ng2-currency-mask ^13.0.3

ng2-currency-mask allows you to format numbers with current, rate with any prefix or suffix you want to add and also custom scaling and format.

When dealing with negative values, it has a limitation, it would allow - only when you have entered any digit, it won't allow you to enter - on a empty text field.

I tried creating a directive on keydown to allow - when values is empty, still no luck.

Is there any way to allow - before entering the digits?

If not, what is the alternative I can use for the above requirements?

Share Improve this question asked Feb 5 at 17:02 Deepak LalithkumarDeepak Lalithkumar 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Considering that ng2-currency-mask isn't being maintained very regularly (with the most recent version being over 3 years old now), it might be worth looking for alternatives such as ngx-mask (NPM entry)

In their documentation, there is an explicit paragraph about allowing negative numbers link, search for "negative"

<input type='text' mask="0000" [allowNegativeNumbers]="true">

Disclaimer: I have not tried this project nor am I affiliated with it, but it looks to solve your issue since the directive approach isn't working and the repo isn't being maintained either.

发布评论

评论列表(0)

  1. 暂无评论