Set value inputmask jquery [closed]

-1

I'm building a small system in jquery and in the part of the edition where I need to inform a value programmatically to the field the JQuery InputMask does not look right. Below the example of my code and what happened on the screen.

$(".money")
        .inputmask('numeric',{"autoUnmask": true,
            radixPoint:",",
            groupSeparator: ".",
            allowMinus: false,
            prefix: 'R$ ',            
            digits: 2,
            digitsOptional: false,
            rightAlign: true,
            unmaskAsNumber: true
        });

<div class="form-group">
     <label>Valor:</label>
     <input type="text" value="0" id="value" class="form-control money watch" required>
</div>

Edit 1 As requested in the comments as I am doing to put the value in the field. PS This trigger I got from a comment in github stating that it worked, I already tried with input too and it still did not work.

    
asked by anonymous 19.12.2018 / 02:23

1 answer

2

I understand your problem, because when you send a value with a dot, example : 150.6 considers R$ 1506,00 and should be: R$ 150,60 , then you have to set correctly the following way, changing the point by comma in the return, like this:

value.val(object.value.replace('.',',')); 

It will work, for example:

$(".money").inputmask('numeric',
{   autoUnmask: true,
    radixPoint:",",
    groupSeparator: ".",
    allowMinus: true,
    prefix: 'R$ ',            
    digits: 2,
    digitsOptional: false,
    rightAlign: true,
    unmaskAsNumber: true
});
$("#BtnSetaValor").click(function(){
  $(".money").val('150.6'.replace('.',','));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/jquery.inputmask.bundle.min.js"></script>

<div class="form-group">
     <label>Valor:</label>
     <input type="text" value="0" id="value" class="form-control money watch" required>
</div>
<br />
<div>
  <input type="button" value="Seta Valor" id="BtnSetaValor" />
</div>

Maybe it's a limitation or even a bug and what's good to do, open an issue and report the problem for the community to try to solve.

    
19.12.2018 / 14:13