problems with jQuery-Mask-Plugin

Asked

Viewed 925 times

0

Guys I am using the jQuery-Mask-Plugin to create masks in the value fields, I liked it because it is very simple.

The problem is when I try to add a negative value it does not accept -. But I reviewed the internet and found a way for it to accept. The problem is that it is not formatting the field correctly.

I will put the code in JSFIDDLE because I could not make it work here.

JSFIDDLE

As you may notice, the formatting has to be the same as

If anyone can help me, I’d be grateful.

I thought about changing something in the project, but I don’t know what I should do. Follow the link of the project code.

https://github.com/igorescobar/jQuery-Mask-Plugin/blob/master/src/jquery.mask.js

  • 2

    https://github.com/igorescobar/jQuery-Mask-Plugin/issues/125

  • had already seen the site, however they are with the same problem that I, the - works, but the number is not formatted

  • 2

    I know, I put the link to the Issue for you to see the author of the project saying that this plugin was not designed for this, and it is not possible to solve the problem with the engine they have developed sustainably. It itself recommends using another plugin to allow negative numbers. Recommended the maskMoney.

  • got it. well I’m already testing it here, if I don’t know how to limit the maximum number allowed, you know how to do it?

1 answer

3

I recommend using the plugin jQuery maskMoney , this plugin will allow you to do exactly what you want in a simple and equivalent way.

Follow an example:

$(function() {

  $("input").maskMoney({
    allowNegative: true,
    thousands: '.',
    decimal: ',',
    affixesStay: false
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://plentz.github.io/jquery-maskmoney/javascripts/jquery.maskMoney.min.js"></script>
<input type="text" />

  • I understand, not the other way to solve the problem of jQuery-Mask-Plugin?

  • You can customize the plugin more will require a massive series of modifications. Even Query maskMoney is a Fork of maskedinput modified for numerical purposes. Do not attempt to recreate the wheel :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.