Input with monetary mask jQuery Mask plugin from Igor Escobar

Asked

Viewed 581 times

1

I implemented the jQuery plugin for masks in form fields developed by Igor Escobar, it is working correctly, but it occurs that when entering numerical values from 1 to 99 take the focus of the field, values from 1 to 99 do not complete the decimal with ".00", some hint of implementation of this possibility in the code?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>

<input type='text' class='money'>
<input type='text' class='money'>

$(document).ready(function(){
  $('.money').mask('000.000.000.000.000,00', {reverse: true});
});

$(document).ready(function(){
  $('.money').mask('000.000.000.000.000,00', {reverse: true});
});
input.money
{
font-size: 12px;
padding: 6px;
min-width: 100px;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>

<input type='text' class='money'>
<input type='text' class='money'>

1 answer

1


It may not be the best solution, but the easiest way to solve it now would be this method, maybe if you searched better in the documentation should contain a solution to this problem with some parameter to be passed

RECOMMENDED LIBRARY: LINK TO DOWNLOAD

$(document).ready(function(){
  $('.money').mask('000.000.000.000.000,00', {reverse: true});
});
$(".money").focusout(function(){
  if($(this).val().length <= 2){
    temp = $(this).val()
    var newNum = temp + ",00"
    $(this).val(newNum)
  }
})
input.money
{
font-size: 12px;
padding: 6px;
min-width: 100px;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>

<input type='text' class='money'>

  • 1

    hi, I searched the documentation, and my doubt and that of other users are open on the github in his profile, has the callbacks but is not resulting in anything this.

  • Okay, I recommend using another library, because I’ve been through at least one problem in this library and what I’ve done is change, I’ll see if I can find the one I used and pass it to you

  • 1

    There’s an error there in the code, "if($(". money"). val(). length <= 2){ ", then it will take all fields with the class and results in nothing, it would have to be " if($(this). val(). length <= 2){ "

  • Thank you for correcting!

  • 1

    https://drive.google.com/file/d/1JyW2KjplXYBkIpCiEhCfN9WrLr0KJxeA/view?usp=sharing Here you are, I hope to help! Good luck

  • 1

    gratitude, needed it badly.

Show 1 more comment

Browser other questions tagged

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