currency formatting error in jquery

0

I'm creating a mask in my field like this:

$("#ValorMultaSt").mask('000.000.000,00', { reverse: true });

When I type some value works perfectly, however when I perform any action on the screen it puts a "." on the front, as in the example:

If I type 444,44 after performing an action on screen the value is changed to .444,44

javascript function:

function AtualizarMascaras() {
            // Mascaras
            $("#ValorPorcentagemField").mask('000', { reverse: true });
            $("#ValorMultaSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaAcrescimoSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaFaixaMinimaSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaFaixaMaximaSt").mask('000.000.000,00', { reverse: true });
            $("#DataPublicacao").mask('00/00/0000');
        }

Function that calls the Refresh Mask function:

$(function () {           

            $(document).ajaxComplete(function () {
                AtualizarMascaras();
            });

            AtualizarMascaras();
});

Div field html:

<div class="row" id="divValorMulta">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <div class="form-group">
                            <div class="row">
                                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                    @Html.LabelFor(model => model.ValorMultaSt, "Valor da Multa")
                                </div>
                                <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                    @Html.EditorFor(model => model.ValorMultaSt, new { htmlAttributes = new { @class = "form-control", disabled, @placeholder = "R$" } })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

Can anyone help me?

    
asked by anonymous 08.11.2018 / 20:47

1 answer

4

You can use another plugin specifically designed for currency masks. MaskMoney

Your code would look like this.

function AtualizarMascaras() {
            // Mascaras
        $("#ValorPorcentagemField").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaAcrescimoSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaFaixaMinimaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaFaixaMaximaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#DataPublicacao").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        }
    
13.11.2018 / 18:31